In this tutorial, I am going to show you how to create animation in 3ds max using maxscript. Many people ask lots of questions regarding this topic like how to create animation using maxscript or how to animate objects with the help of maxscipt alone. This tutorial will show you how to do this in a few simple steps. It involves writing a short code to demonstrate how it works and its implementation on a practical example. So, let’s get started.
Step1
Let’s first open the maxscript editor through MaxScript > maxscript editor. Now, we need an object to animate. You can create any primitive you want using Create panel but you can also create these primitives by simply executing a single line of code.
my_obj = box ()
This will create a box at [0,0,0] coordinates. Similarly, you can create any primitive like Cylinder, Teapot by writing a simple line.
my_obj = cylinder() --creates a Cylinder. my_obj = teapot()--creates a Teapot.
Step2
Here, I added some more lines to finish the code. I tried to make it very simple so that those who don’t know much about maxscript, can easily understand what’s going on.
Code:
my_obj = box() with animate on ( at time 50 move my_obj [50,0,0] )
Explanation:
my_obj = box()
This line will create a box geometry at 0,0,0 coordinates.
with animate on
We use this function to create keyframes. If we don’t use this function then no keyframes will be recorded.
at time 50 move my_obj [50,0,0]
This line will move the box at 50th coordinate of the x-axis at time / frame 50. Let’s evaluate the script by pressing Ctrl + E. You will get something like this:
Now, we have better understanding of moving an object using maxscript though it’s not a big deal to move an object so let’s try something complex than this.
Step 3
Here I have a meter with a needle on it and we have to animate the needle on it’s z-rotation with the help of maxscript.
Code:
with animate on ( at time 10 $needle.rotation.z_rotation = random 100.0 -100.0 )
Explanation:
Here, we have a very short code to randomize the rotation of the needle. The code is pretty much the same as before. I just modify it by adding a line
$needle.rotation.z_rotation = random 100.0 -100.0
With the execution of the given line, 3ds max starts searching the object with name needle and rotate it at a random degree from 100 to -100 at z-axis. Let’s evaluate the code by pressing Ctrl + E.
You can clearly see that it just created keyframes at time 0 and 10 with the needle rotated at a random angle but let’s say we want that random needle movement until frame 100 or whatever range we want. We can do it EITHER by using at time function several times to randomize the needle’s rotation on timeline. For example,
with animate on ( at time 10 $needle.rotation.z_rotation = random 100.0 -100.0 at time 20 $needle.rotation.z_rotation = random 100.0 -100.0 at time 30 ... )
OR we can make use of For loop to repeat the action several times. I recommend For loop as it’s the fast way and keeps the code short and simple. Let’s do it in the next step.
Step 4
with animate on for i=0 to 100 do ( at time i $needle.rotation.z_rotation = random 100.0 -100.0 )
Here, For loop will repeat the rotation command several times. Since the For loop’s variable i has the value range of 0 to 100 and we are using it as time, it will create keyframe for each frame.
Handling too much keyframes is quite difficult task so, in order to avoid creating keyframes at every frame we have to modify the For loop as,
for i= 0 to 100 by 5 do
This will create keyframes after every fifth frame so the code would be:
with animate on for i=0 to 100 by 5 do ( at time i $needle.rotation.z_rotation = random 100.0 -100.0 )
Here is the final result:
I hope you liked the tutorial. Go ahead, modify the code add some more logics and have fun with MaxScript. For any suggestions or queries you can email me or just leave your comments below. Thanks ;)