Notifications
Clear all

[Closed] Proper way to get an array of keyed times

Hey all,

I’m trying to execute a certain action at the time when a certain object has a keyframe. For example, a certain bone in my character has a keyframe at frame 9, 22, and 55 and I want a maxscript to be able to get those 3 numbers into a proper array.


 animate on (
 	controla = bone.controller
 	for i in 1 to controla.keys.count do (
 		if(controla.keys[i] != undefined) then (
 			realkeys[i] = getkeytime controla i
 		)
 	)
 	j = 1
 	for t in 1 to 90 do at time t (
 		if(t == realkeys[j]) then(
 			-- DO SOME ACTION HERE, AT TIME 9, 22, and 55 IN OUR EXAMPLE
 			j = j+1 -- increment j , apparently you cant do j++?
 		)
 	)
 )
 

As you can plainly see I’m a Maxscript beginner but would appreciate some help getting the getkeytime to be used as I need. It returns “22f” if I’m not mistaken so would I have to chop the ‘f’ off of it and then tell maxscript to use it as an integer? I’m kind of at a loss of how to pull this off. Thanks for any assistance.

2 Replies

[/i]

instead of using getKeyTime you can use getKeyIndex …

[i]

[/i]
[i]keys = for t in #(9f, 22f, 55f) collect[/i]
[i]([/i]
[i]if (i = getKeyIndex <controller>[/i] t) == 0 then [i]undefined[/i] else (getKey [i]<controller>[/i] i) 
)

in this case you will get list of keys in right order (and undefined if there is no a key at the time)

every MAXKey has #time, #selected, and #value properties
you need <key>.value
#value property varies by key’s containing controller

Now is about “[color=yellow]time format”…[/color]

a = 10f means that variable a is “[color=yellow]Time” class value[/color]
if you want to get frame (integer) value you have to call a.frame

DenisT, you rock.