The power of the one-liner

Sometimes you just want to tell max to do something and it seems rediculous that there isn’t a button already there to do it. Often the code behind it isn’t even that complicated, I get asked quite a lot for a quick script to do something and often it can be done in just one line of Maxscript! These are what I call the one-liners and is one of the most powerful things you can learn to do in max.

Some examples of one-liners, see how similar the actual code is to just writing it out in english, albeit a geeky-grammar based language, perhaps one day our language will evolve to be able to communicate with computers in a way they understand more, things like Siri can understand basic instructions but if we want to get to the Star Trek level of talking to a computer we either need computers to be able to understand our often unclear English or adjust the way of speaking to make it clear.

Make the material in slot 1 of the material editor the current object’s material, just because it’s a pain to pick some times.

meditmaterials[1] = $.material


For every object in our selection where the material is not undefined put it in the material slot of the same index (will bug after 24)

for i = 1 to selection.count where selection[i].material != undefined do meditmaterials[i] = selection[i].material


For every instance of the class Turbosmooth in the scene set the render Iterations to the same as the display iterations

for o in getclassinstances Turbosmooth do o.renderIterations  = o.iterations


For every object in selection change the wirecolor to a random colour

for o in selection do o.wirecolor = color (random 0 255) (random 0 255) (random 0 255)


select every object in the objects where the object’s material is not defined

select (for o in objects where o.material == undefined collect o)

Put any requests for simple one-liners in the comments section and I’ll see if they can be done in one line of code.


About davewortley

Somewhere between an artist and a programmer, I like technical things, but being creative. I love problem solving and coming up with elaborate solutions. This blog is where I shall share ideas, tips, tutorials and anything that amuses me.
This entry was posted in 3dsmax, MaxScript. Bookmark the permalink.

5 Responses to The power of the one-liner

  1. Very helpful. I still have trouble finding classes and objects to code with in Maxscript. I feel the help document isn’t laid out as clean and simple to follow and find objects and classes. I mean, here in this post you call your Turbosmooth class and renderiteration class so you can modify them. I just dredge having to dig up data like this. I know I sound very lazy, but who isn’t.


  2. algis says:

    The help file is as clear as mud… It seems like AD never wanted us to understand their scripts 😀


    • davewortley says:

      You need to learn the basics then you’ll be able to understand the help, see my post on understanding the help file and then you will be able to learn lots more.


  3. Dwayne Ellis says:

    Thanks for these! Great site as well….very helpful!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s