So, you’re new to Python or even Maxscript and you think now it’s the time to get your hands dirty and start doing some code right?! Right! Let’s start with the pretty basic stuff.
How to get the selected nodes in 3dsmax and print out their names? How about all scene objects? Easy.
import MaxPlus def getselectednodenames(): for node in MaxPlus.SelectionManager.Nodes: print node.Name def getscenenodenames(): for node in MaxPlus.Core.GetRootNode().Children: print node.Name if __name__ == '__main__': getselectednodenames() getscenenodenames()
Pretty easy hein!? Now let’s check how to add a modifier to a selection:
import MaxPlus def addmodifier(nodes): for node in nodes: mod = MaxPlus.Factory.CreateObjectModifier(MaxPlus.ClassIds.Noisemodifier) for param in mod.ParameterBlock: print param.Name mod.ParameterBlock.seed.Value = 12345 node.AddModifier(mod) if __name__ == '__main__': addmodifier(MaxPlus.SelectionManager.Nodes)
Be sure to look at the class definition in MaxPlus.py for the ClassIds, there you’ll find the name of all the modifiers (along with other classes) you can currently use with python. Also, here we are using the CreateObjectModifier, but if you want to add a WSM modifier you’ll need to use CreateWorldSpaceModifier instead.
Also accessing the parameters is still not that straightforward, hence I’ve included a print out of the ParameterBlock, where all the parameters for the modifiers are stored, to access those parameters, change them, you’ll need to use “modifier.parametername.Value”, take note of the uppercase in Value and that should be it, now you just need to add the modifier to the object with AddModifier().
Hope this gives you a small intro to the new and recent python in 3dsmax!
8 Responses
flo
def getscenenodenames():
for node in MaxPlus.Core.GetRootNode().Children:
print node.Name
gives you just unlinked objects right? but not all scene objects
Felice DeNigris
I am trying to start python in 3dsmax 2015, but my knowledge of python is very little and the documentation is poorly written. I am wondering why I type import MaxPlus in 3dsmax listener and nothing happens? But if I type import MaxPlus * it suceeds?! Which way is the most effective way of using python in 3dsmax for a beginner? With Listener? Or a third party editor(which I’m not too fond of) Thanks for your efforts in this blog.
Artur Leao
Hi Felici,
Thanks for your kind words. I guess the best place to start would be the python developer help. Use the Maxscript listener and go to File and open a new editor window.
You need to have either a python file and use: python.executefile pathtothefile
OR you have a string where you write your code in python and then execute it with: python.execute string
Where pathtofile and string are the path to the python file and the string containing your python code.
I hope this helps and I can write a blog post for beginners soon, soundes like a good idea 🙂
Felice DeNigris
Thanks so much!! I guess for me I will write lines of code in python and use python.execute string for intro purposes. Thanks alot. An intro tutorial would be awesome!
Felice DeNigris
Does the SelectionManager class have a ‘Node’ Method? I don’t see such method in the documentation. I see GetNode()
Spencer
God if only I found this 3 hours ago!!!
Spencer
What’s the difference between MaxPlus.SelectionManager.GetNodes() and MaxPlus.SelectionManager.Nodes? They both seem to work the same for me.
zhang
How to change the Unwrap_UVW ‘s parameter of Modifier?? Change Map Channel for 2 ???thanks