Scripting for Artists in 3ds Max

Scripting for Artists in 3ds Max

Hello and welcome to my introduction series of
Scripting for Artists My name is Alexander Richter and today we want to have a glimpse look into
Scripting in 3ds Max So before we dive in
let’s have a look in the scripting languages
we can Script in 3ds max: The first one would be Max Script which is best used for a specialist
since it can ONLY be used in 3ds Max But on the flip side it’s a native language
so it’s well integrated and gives you quite amount of
feedback and help On the other side
We have Python which is best used for Generalist
since you can use it across all the DCC packages You will normally have in VFX and Animation
from Maya to Nuke to Katana etc. But you can say it`s some kind of fresh addition. It’s already there for some years
but it’s still not 100% well integrated and it provides you with just partial help and feedback Lets compare both code sides of
MaxScript and Python So we want to open the test.max For MaxScript we would say loadMaxFile and then we give it the file path in quotes In terms of Python:
We would first need to import the 3ds Max API So we say:
import MaxPlus and then we say:
MaxPlus we want to access the file manager and then we want to use the function open
and give it also the path Let’s fire up 3ds Max While it starts Let’s compare Maya and 3ds Max
since they have some similarities Especially in the native language in Maya we have MEL
in 3Ds Max we have MaxScript and both are native languages in their software packages and have a specific amount of feedback
you can use and trigger Which I will show you In terms of Python it’s both an addition and especially in Maxscript
it’s still not very well integrated in some parts you can even say:
It’s some kind of trainwreck If you don’t you are not used to use Python and still just want to use 3Ds Max and help your your daily life I would suggest to go into MaxScript and just look up the basics how to do Max Script Let’s dive in So if you look at the menu
you have a scripting tab if you open it up
you have MaxScript Listener and MaxScript Editor So the MaxScript Listener is some kind of a console
so it’s the output of what you do and it provides you with the options of using MaxScript or Python We stay at MaxScript
and you can tip in commands in the Listener but i wouldn’t suggest it because then you will mix up input and output
so use it mostly for outputs. On other side
We have the MaxScript Editor which on one side a normal file editor
and the other side you can execute code directly Let’s dive in into MaxScript
and do something So we have here The open file code To open a file we say:
loadMaxFile then space
and then in quotes we write the file path To execute anything in MaxScript Editor You either execute the whole file or tab So you press:
CTRL+ E If you want to have a specific selection executed just select it and press:
SHIFT + RETURN So now we executed the loadMaxFile
and as you see we changed to test.max We printed it out
it’s true so it works So for saving it’s intuitive quite the same now So it’s Instead of loadMaxFile
its saveMaxFile saveMaxFile
and then a Path Let’s execute this one And now we changed the save from test to test2. So maybe now you want to have the scene path How do you get? MaxScript has besides some functions of Course Variables and two of them are maxFilePath and maxFileName and if combined with a +
we get the same path and scene name If we execute this one
we would get this path here so it’s test.max where we currently saved them So now you ask yourself like
How do i know all this stuff? There’s a lot of functions and variables
and how do i know it? and my first answer would be Google it.
If you want to know for example the path of the current file just type in: scene path MaxScript and one of the first links will provide you probably exactly that line of code which i used now the other way which is the same way in Maya is Doing something and printing it out Copy it, change it and then execute it It’s the same way
as you use it in MEL you you have a function here and it’s called MacroRecorder you can find It in the MaxListener If you enable it it will record everything you do and print it out as a MaxScript command so let’s do something here Let’s go to CREATE/primitive
and let’s create a box primitive Now we create a box print out anything As you can see
We have already the first code of how to create this box primitive and with specific scale and rotation etc So let’s continue our work
Let’s move it a little bit rotate it and scale it Now we are finished.
We disable it. We have a decent amount of code
We now can use to modify as we like so let’s bring it here And let’s do a scale
so we know how to scale now We put it in a Script Editor that the command here is “scale” Then it’s a $ which means the current selection and then we have some variables for xy and Z So let’s double this current size select this SHIFT + RETURN And as you can see we doubled the size of the current selection but what is if you don’t select something at the moment and you want to access specific object in the scene easy as that is just The selected and here you see the name so it’s called box001 So if you would add to your $ $box001 and then execute this line You would access the specific object in this scene so a way of doing is just replacing the selection with the real name of the object and then you can access it and you can use from everything here inside you can use the move tool to change things you can use the SelectionTool to select
specific parts of your scene you can even create the whole object through that and this is like the easiest way of accessing MaxScript for you Just start the MacroRecorder,
do some stuff Copy that,
change what you need and how you like it and then execute the parts which you want to do So next up would be how to do ui so now you you have your Chain of Things to do but you want Maybe Changes sometimes You want to have specific objects and you want to type it in or Select Them inside a ui and Yeah There’s a Way in max triplets Called Rollout and Let’S have a Look of What This Would Be iF we Execute this one? So we Would create a window with a small roller Inside there so what did we do So we Say we want. To create a roll out The Variable name is Now New roll out The Title of The is will be New roll out Which as you can see here and then The size we have in Height and? I mean It would be an empty roll Out so it’s nothing there so let’s create a button for there so button is Just Inside the Roll out you will say Button then it Will be Called Button one from now on and The content of The Button Would be do something Which is here Then the Position of The Button inside this and then The widow fin Heart But of Course a Button With no Function is not of a Button so we need to add a Callback for that so we Say On button one we want the press event and If you press it do do a print here at mini backside and Open a message box and Say finish Doing Stuff so if we press it Forget The message box finish Doing Stuff and it Will print in a background to print one and you can Put in a Lot of Other Things Like Other Mac script Things like for Example move the Current Selection Change the current Selection and This is the way and We’re not Finished here because we Just have to roll it but we don’t. Have a window? So one Way It would be to do a new Roll Out floater we Call It big window Set The size here so it does This is still the Whole big thing and In the end we Need to put the small robot Inside the big window so we Say Add roll out You Roll Out Button Thing and That’s It and That’s That’s like an Easy Way of creating Ui and Making accessible For Your Needs but on the other side it’s the same Way with the macro recorder you can do it like By Code Googling It in this way or you can use it visually and how to do that so you go into scripting and Here is the Visual Mac script editor and It’s a ui to create your ui so let’s create a Very clunky Very Fast Paced ui here so what we Want here one color Picker Checkbox we don’t know we don’t care so we create It Now and you Now you can Modify How everything is Called How What’s the size and so on and so on When you’re Finished you Just Say file save as and then You save It As a Mac script file So let’s call it New ui and save it But you’re not Finished yet Because now it’s Just You can’t access it at the moment so what you need to do Is to give it a window so we learned that before so let’s copy Copy the code here So yeah we have a Big window and it’s called Unnamed Rollout so we need to change it here and save it So yeah so now we have Saved our current ui in a file so how can We Access it to access any file here You Need to do two Things at first You Need to copy the file into a path Where 3dS Max Know there is a script file and one of The paths you Freeze Max is accessing is Under C users you’re Logging name F data local autodesk 3dS Max Then the version Menu and scripts it’s a Mouthful but This is one of the Paths 3ds Max Is accessing and Waiting for scripts to be there so if we Put our new ui ms Inside there we can Access it in our script editor for Example We want to access this one Which we create it now so we Say file in and then give It a name and As you can See We create Our Monstrosity of a Rollout with all the color Picker and The Check box and Check button and and so on and this is like The easiest way Just create in Visual Maxscript Editor Your Roll out Added To save It in your script for path and then You can access It and you can Still Add Buttons and Functions to that Thing so in the same Way you can Access like code if you Just Have so Example a Function so for Example we have also in this path The lord Ms File Here so What’s inside there So we Load the max file test okay So the same way how to access this is Just to do file in and then Say Lord Ms so let’s Exit this and Now we change from test to to test and this is like The way of accessing any files and have? Inside Instead of Always Into Your script Editor Compromised in one file and Just use one line of code to add like a Bunch of Things to your scene So the Other Way the thing is i want to mention is of course the pyThon? It Will be a Little Bit smaller since Python is not as Advanced as It can be But Let’s have a look into that so first Thing We Need to do is To how to import 3dS max Api so we say Import Max Plus and Let’S do a safe so we already Saved so let’s do a test one Yeah and We Save test One and the same Way is like Max Plus file manager safe and Max Plus file manager open you save and open Plans so There’s a Certain Situation Where you sometimes don’t know something in python but you know it in Maxscript Because for Example you use the macro recorder and now You don’t know what to do because you want. To use python and there’s a Way Where you can Put Python Around Mac script and the Way to do it is use Max Plus dot core and then use the function eval Max script and Inside in quotes you put in the mac script command and if You for Example want to get Print something Out or some or have some Informations like in this case the file path you Need to add dot Get So if you would execute this line Here? We Would Get the current file path and Now we use python with Mac script inside to To execute this line and We If we for Example novum Extra Command we Can Still Use pi for that and It sometimes can Be Very Very Handy in this case So the last Thing i want to show you is the same Thing as a Mac script i want to show you how to access External Files a Pity Thing in pipes But especially Here at videos Max Is pi from accesses environment Variables and 3ds Max Doesn’t Work That Much Within my Rebel’s so If you want to have an access to a pi from file Within the file you need Need to add It As a Variable To the current System so a Way to do it is to do an import Sis and Then Say Sis path append and then add a Path for Example ii Alex So here we have the Alex and we Have here for Example? The Save script Pi and What’s in there It’s Just a Function Safety and Just Safe to test free That’s it so if we Would Execute This Lines Which we Say Add This path This folder and then Use the save script for a file and Access there the safe Seed Function so let’s Actually execute this one And as you can see we Changed from test one to test three and Saves It as test free so this is like The basic way of How to work in 3ds max with Max script and – and i will Highly Recommend John Wainwright’s Maxscript 101 he is the creator of Mac script and also for me was the the basic introduction for Mac script and 3ds Max i Hope You Like This video and share It With People Who are interested in learning Scripting and i will see you in the next video Goodbye you

13 thoughts on “Scripting for Artists in 3ds Max

  1. Hi Alexander, new to Max here. When I started learning how to use python and MEL for maya – the process was very easy to learn thanks in large part to the easy to search command list on the autodesk website, it provided examples too. I was wondering if Max has a similar website where you can search a command list like in Maya. my searches have been pretty fruitless

  2. The macro recorder is not generally good for learning how to write scripts of your own as it mostly shows what internalized actions are bein run with little exposure to the constructors. Use show in the listener to get the accessible attributes, as in show($Obj) when looking to manipulate any type of asset. You can use show for connected nodes too. show($Obj.material). Been using maxscript for a loooooonnngg time. Prefer Maya as its Python integration is far superior to the mess they made of Maxplus and pymxs, though the latter is the better of the two as its closest to Blur python, but pymxs has NO docs, but they are creating some now after community feedback

  3. Scripting in 3ds Max is no cakewalk but it is manageable and here is how.
    What topics in 3ds Max are you interested in?

  4. Possible to make a floating character UI using MCG?
    I'm not new to max….been using it since version 4….over 20 years……just never messed with the MCG stuff yet.

  5. Hi Alexander thank you for your efforts , i have a problem with a script which is not compatible with 3ds max 2018 it's dedicated for earlier versions so do you have a solution please

  6. hello can you make more video about python on 3ds max how to aasset manager or bigger project also please make video how to read and using 3d smax python sdk

Leave a Reply

Your email address will not be published. Required fields are marked *