Notifications
Clear all

[Closed] how to get animation range of object

I have camera which is animated from frame 0 to frame 350 and it has 4 key frames in between now how can I get this animation range.
is there any function available to do this?

9 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

Controller Time Functions[color=white] Time Range Operations:[/color]

[left][b][b]getTimeRange[/b][/b] <controller> [  #[b][b]selOnly[/b][/b] ] [ #[b][b]allKeys[/b][/b] ] [ #[b][b]children[/b][/b] ]

[/left]

to get time in frames (integer) you can ask time value property #frame


animationrange.start
-- 0f
animationrange.start.frame
-- 0.0
animationrange.start.frame as integer
-- 0
    
--animationrange.start
    --animationrange.end
    --for obj in objects where classof obj == targetcamera do collect obj
    sortKeys $.controller
    num_keys = numkeys $.position.controller
    starttime = getkeytime $.position.controller 1
    endtime = starttime
    for i = 1 to num_keys do 
    (
    	
    	key_time = getkeytime $.position.controller i
    	if key_time > endtime then
    		 endtime = key_time
    )
    format "start: % ; end: %
" starttime endtime
you can use the animationrange.start() and animationrange.end() for getting the start and end range of the animation but if the position key frame for the object is outside this range you can use the above uncommented code. make sure to select the camera and then run the script.

edit *: here’s a better way ! :

sortkeys $.controller
arr1 = $.controller.roll_angle.controller.keys
arr2 = $.scale.controller.keys
arr3 = $.position.controller.keys
arr4 = $.fov.controller.keys
endtime = 0
for i = 1 to 4 do
(	
	if (execute ("arr" + i as string + ".count")>0) do
	(
		key_time = (execute ("arr" + i as string + "[arr" + i as string + ".count]"+".time"))
		if key_time > endtime then
			endtime = key_time
	)
)
format "endtime = %
" endtime

Thanks HornBerger, thats what I want.

now how can I change the frame value to integer? like 100f to only 100.

1 Reply
(@pixel_monkey)
Joined: 11 months ago

Posts: 0

From the Maxscript Time Values page:

Time Values[left]<time> as <class>
[/left]
[left]You can coerce a time value to an Integer or Float number – you get the time in ticks

currentTime
  35f

[/left]
[left]

(currentTime as integer)/TicksPerFrame
  35

-Eric
[/left]

sortkeys $.controller
total_controller = 3
arr1 = $.controller.roll_angle.controller.keys
arr2 = $.scale.controller.keys
arr3 = $.position.controller.keys
if $.fov.controller != undefined do
(
 arr4 = $.fov.controller.keys
 total_controller+=1
)

endtime = 0

for i = 1 to total_controller do
(	
	if (execute ("arr" + i as string + ".count")>0) do
	(
		key_time = (execute ("arr" + i as string + "[arr" + i as string + ".count]"+".time")) 
		if key_time > endtime then
			endtime = key_time
	)
)
tempArr= filterstring (endtime as string) "f"
endtime_int= tempArr[1] as integer
format "endtime = %
" (endtime_int)

look at the code in cyan

cheers!

i can’t get the gettimerange function to work for example i animated the position of a sphere from 0 to 20 and then execute the code:

at time 5 animate on ($sphere01.pos = [0,0,100])
 a = getTimeRange $.position.controller
 a.start.frame
 a.end.frame
 supportsTimeOperations $sphere01.position.controller
 

and gives me this output:

[0,0,100]
(interval -1.34218e+007f -1.34218e+007f)
-1.34218e+007
-1.34218e+007
false

i was expecting the output to be 20f for the end frame and 0f for the start frame but it is not so. instead it says false for supportsTimeopertaions command for the sphere position controller
any one kind enough to explain this to me !

any help is appreciated thanks ! cheers !

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

because your position controller is Poisition_XYZ. you have to ask time range from sub controllers:


gettimerange $.pos.controller[1].controller

thanks a LOT Denis :bowdown: your the best!

Thanks Charlesbary and Denis for your valuable solution