Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Set frame range to include all frames with animation on selected objects?

Set frame range to include all frames with animation on selected objects?

Anonymous
Not applicable
1,847 Views
2 Replies
Message 1 of 3

Set frame range to include all frames with animation on selected objects?

Anonymous
Not applicable
Relative newbie here in Maxscript and would appreciate any help.

What I want to do is set frame range to include all frames with animation on selected objects.

This is ultimately so I can Export Selected to .FBX a specific set of objects, baking the keys to include any animation - in a batch. The current frame ranges are often only a small section of the full animation, but I want to export all the animated frames.

I'm sure there is an easier (or more complex, but quicker) way of doing this, but here is what I have so far:

--make my selection
--(I don't have a problem scripting this, obviously will vary depending on the project)

--setting the range to be large enough to include all animation in most of my files

animationRange = interval 0f 10000f

--setting the current frame to 10000

sliderTime = 10000f

--toggling on the Key Mode Toggle
--then going to Previous Key

sliderTime -= 1 --according to the listener, this command is the same whether the Key Mode Toggle is on or off

--then setting the EndFrame to the Current Frame

animationRange = interval 0f sliderTime

--btw setting the StartFrame to frame 0 trusts that no segments start before zero, which might not always be true
--that would capture all animation from 0 to highest numbered keyed frame

Problems:

How do I toggle the Key Mode Toggle via maxscript?

The listener is wrong, even with the Key Mode Toggle on, 'sliderTime -= 1' just goes back one frame, not to the Previous Key. How do I do that?
0 Likes
1,848 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Pretty cool thinking!
The -=1 does not jump to the previous key, You have to use 'max time back' and have to be in 'max key mode' to do it, but there appears to be no good way to check whether it is set or not. Here is a version of your idea that might work:

fn bracketAnimSelected =
(
animationRange = interval -10000 10000 --#set the large interval
theTime = sliderTime = 10000 --#set the slider time to last frame
max time back --#press the back button
keyModeSet = false --#set a flag whether key mode was set or not
if sliderTime == theTime-1 do --#if the result was one frame back,
(
max key mode --#toggle key mode
max time back --#press the back button again to jump to prev. key
keyModeSet = true --#raise the flag because we turned key mode on
)
lastFrame = sliderTime --#remember the last frame
sliderTime = -10000 --#set the slider time to first frame
max time forward --#jump to next key
animationRange = interval sliderTime lastFrame --#set the range from first to last
if keyModeSet do max key mode --#if turned on by the function, turn key mode off again
)

bracketAnimSelected() --#call the function
0 Likes
Message 3 of 3

Anonymous
Not applicable
Works perfectly! Thank you! 🙂

Ted

Credits and ()'s added so I could test it in a menu as a macroscript:

macroScript BracketAnimSelected category: "Export_Tools"
--BracketAnimSelected
--by Borislav "Bobo" Petrov
--June 23, 2008
--This is meant to set the frame range to fit exactly around any animated keys for the selected objects
--
(
fn bracketAnimSelected =
(
animationRange = interval -10000 10000 --#set the large interval
theTime = sliderTime = 10000 --#set the slider time to last frame
max time back --#press the back button
keyModeSet = false --#set a flag whether key mode was set or not
if sliderTime == theTime-1 do --#if the result was one frame back,
(
max key mode --#toggle key mode
max time back --#press the back button again to jump to prev. key
keyModeSet = true --#raise the flag because we turned key mode on
)
lastFrame = sliderTime --#remember the last frame
sliderTime = -10000 --#set the slider time to first frame
max time forward --#jump to next key
animationRange = interval sliderTime lastFrame --#set the range from first to last
if keyModeSet do max key mode --#if turned on by the function, turn key mode off again
)

bracketAnimSelected() --#call the function
)
0 Likes