Animation

Getting and setting the frame range

When you get or set time intervals via the API, intervals are represented not as the number of frames, but instead as the number of frames multiplied by the number of ticks. Each frame contains 160 ticks. Therefore, intervals are represented as number of frames x 160.

Therefore, when you get or print values, you need to divide the interval by 160 to obtain the actual frame number. Likewise for setting values.

Use Animation.GetAnimRange() to get your animation range. The default value is 100x160.

The demoAnimation.py example defines a PrintInterval method that divides intervals by 160 and prints the results in terms of frames. In this example, Animation.GetAnimRange() is used to obtain the default frame range, then the PrintInterval method is called so that the frame range can be printed out in a user friendly way, in terms of frames:

anim = MaxPlus.Animation
PrintInterval(anim.GetAnimRange())

Creating intervals

There are two constructors for the interval class:

When calling the second constructor, remember to multiply the number of frames by 160 ticks again. You can then set the frame range using Animation.SetRange():

newFrames = 200 * 160
newRange = MaxPlus.Interval(0,newFrames)
anim.SetRange(newRange)

Setting the keys to your animation

To enable the Auto Key button, call Animation.SetAnimateButtonState(True).

To set each keyframe, set its time, and move your object. Remember to multiply the frame number by the number of ticks. The demoAnimation.py example demonstrates these steps as follows:

doRedraw = True

# Advance the time slider to frame 30
anim.SetTime(30*ticks,doRedraw)

# Move the sphere; this creates a keyframe
sphere.Move( MaxPlus.Point3(50,0,0) )

Turn off the button after setting your keys by calling: Animation.SetAnimateButtonState(False).

Playing back the animation

To playback an animation, call Animation.StartPlayback(int selOnly). There are two versions of this method; call the version that takes an integer as input.

You can set whether or not to play the animation as a loop by calling: Animation.SetPlaybackLoop().

To rewind back to the beginning of the time slider, for example, so that you can play the animation a second time, call: Animation.SetTime(0, True). An example is as follows:

anim = MaxPlus.Animation
    
anim.SetPlaybackLoop(False)
OldStyle = 1  
# Important: provide an integer value as input to StartPlayback
anim.StartPlayback(OldStyle)
    
anim.SetTime(0*ticks,doRedraw)
anim.StartPlayback(OldStyle)

Playback speed

Animation.SetPlaybackSpeed(int s) takes only five discrete integers as input. To avoid guessing the previously undocumented values, the class PlaybackSpeed was written in the demoAnimation.py example. This class defines acceptable values that can be passed to Animation.SetPlaybackSpeed(). Therefore, to set your speed, you must first refer to the dictionary for the corresponding integer value for your desired playback speed before calling this method.

For example:

anim.SetPlaybackSpeed(PlaybackSpeed.X4)

This command calls the previously defined PlaybackSpeed class to obtain the integer equivalent for the quadruple time playback speed (X4), then passes the integer to Animation.SetPlaybackSpeed().