MAXScript / pymxs expose several functions for working with animations in 3ds Max.
The animation range is held in the animationRange
global, which holds an Interval value. Intervals represent a range of time. So for example to get the frame range and change it:
>>> pymxs.runtime.animationRange
<Interval<(interval 0f 100f)>>
>>> pymxs.runtime.animationRange = pymxs.runtime.interval(0,200)
Animation keys can be set using the pymxs version of the MAXScript at time
context expression, pymxs.attime()
. Note that pymxs.animate()
must be set to True first if you are setting keys. If you simply want to inspect values at a specific key frame, you do not need to set pymxs.animate()
.
The pymxs.attime()
context expression takes a time value, which can be expressed as ticks, (4800 per second), frames, hour/minute/second, or normalized time. See the Time Values topic in the MAXScript Help for more information. For more information on context expressions in general, see the Context Expressions topics in the MAXScript Help.
rt = pymxs.runtime
t = rt.teapot()
with pymxs.animate(True):
# go to frame 0
with pymxs.attime(0):
t.pos = rt.point3(0,0,0)
# go to frame 100
with pymxs.attime(100):
t.pos = rt.point3(0,10,100)
pymxs
provide two functions for controlling animation: playAnimation()
and stopAnimation()
. You can query whether animation is playing with isAnimPlaying()
. For example:
>>> pymxs.runtime.playAnimation(immediateReturn=True)
>>> pymxs.runtime.isAnimPlaying()
True
>>> pymxs.runtime.stopAnimation()
True
To set the playback speed, use the timeConfiguration.playbackSpeed
setting. For example, to set the playback speed to 2x:
pymxs.runtime.timeConfiguration.playbackSpeed = 4
To get the current time on the time slider, use the currentTime
global:
# get the current time as a time value:
>>> rt.currentTime
<Time<13f>>
# get the current time as a frame:
>>> rt.currentTime.frame
13.0
All of the settings on the Time Configuration dialog are exposed to pymxs/MAXScript. See the "Time Configuration Dialog" topic in the MAXScript Help for more information.