Basically, what I'm trying to do is create a button that automatically adjusts the animationRange to the amount of keyframes on a selected object.

So if an object it's last key frame is on frame 120, and the animationRange is currently at 0-70, pressing the button automatically makes the animationRange 0-120.

I kinda got this to work, but not quite.

The thing is... I have know exactly how many keyframes are on the object, and take the last key Index and put it in the variable below ("last'). The problem is, each object doesn't have the same amount of keyframes.

The code below works just fine if the object in question just happens to have 3 key frames.

How can I make it find the last key frame, put that number into "last" variable?

If you are only animating the position, rotation and scale of the object it's really simple, but if you need to support modifiers, custom attributes and pretty much anything else, unless there is a way to maxscript "see" the keyframes shown in the track bar, things may get a lot more complicated than you think.

As I haven't found a way to directly get the keys in the trackBar, in a script that I did for removing unnecessary keys and flat curves I needed to do the whole navigation through controllers mySelf, and that's the complicated part if you haven't much experience with scripting. But it's not that hard too...

Well, if you want to get the first and last keys, regardless of their amount, try this:

first = $.pos.controller.keys[1].time
last = $.pos.controller.keys[$.pos.keys.count].time
animationRange = interval first last

The property &quot;.keys&quot; of a controller is an array with all the keys of that controller, so the first and last items of this array are pretty much the first and last keys of the controller.

This is just for you to have an idea, I'm only showing how to be time and key amount independant. But what you should really do is to navigate through all the controllers of the object to store the correct first and last keys.

Hope this helps a bit...

Regards,

Jr.

CGTalk Moderation

03 March 2008, 08:05 PM

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us on TheArtSociety.com