Saturday, March 29, 2008

Simple scripting

Scripting in 3ds Max is maybe not for everyone, but I couldn't even begin to count the hours/weeks/months of my time that was saved by learning at least the basics. You don't have to be a scripting genius to automate some simple repetitive tasks. The "For loop" is very basic, and is also probably the most common bit of coding you'll need. Save yourself hours of work and try this.

Lets say you've modeled a bunch of vines using renderable splines (based on a true story), but after placing about 300 of them you realize you forgot to give them enough segments to look rounded. The "for loop" is here to save you. It goes like this.

---------------

for i in selection do
(
i.render_sides = 12
)
-------------------

Its that simple. But let me explain what its doing. "i" could be anything. It could be "n", "blah", "Myfirstofficialblogpost"....etc. It doesn't matter. Its a variable that you make up that will represent each object in your selection. So basically....for (every object) that is selected do...the following bit thats in parenthesis.

In this case inside the parenthesis is a line of code that will change the segments a spline to 12. Because "i" will represent every object in my selection. This script will go through each object in my selection one at a time and change the segments to 12.

Now lets take this one step further. Another really helpful bit of code to know is how to generate random values. With a slight modification you can have the above script assign a random number of segments to each spline.

-----------------------------

for i in selection do
(
X = random 3 16
i.render_sides = X
)

-----------------------------

So in the above situation all we've done is create a variable called "X" which for every object in the scene will generate a random number between 3 and 16. Then the script assigns that value to the segments parameter of one of your splines and repeats the process until it has done this to every object in your selection.

You can use the Maxscript help file to look up what a certain parameter is called, or you can open the maxscript listener and adjust the parameter you want to later script and watch what code appears in the listener. Its an easy way to get the line of code you need without having to open the help file and search for it.

Its pretty simple stuff, but its saved me countless amounts of time. Enjoy.

Thursday, March 27, 2008

First Post!!

I've been wanting to start a blog for a while, but hadn't gotten around to it. I guess the stars aligned and it finally happened. Anyways, the idea was to have a place to just ramble out ideas and tests related to CG, compositing and photography. Maybe some experiments, tips and tricks I've come across, tutorials. Whatever seems interesting.