[Closed] [Pymxs] How to get the first and last frame of an object
I’m trying to get a certain object and find the first and last frame of the object. I have the following below so far, where it’s getting the camera object. I know to use animationRange to get the whole animation range, but i’m unsure how to specify it to one object.
camera_VR = "VR"
for camera in rt.cameras:
if "VR" in camera.name:
vrCam = rt.getNodeByName(camera_VR)
timeRange = rt.getTimeRange(vrCam)
start_frame = timeRange.start
end_frame = timeRange.end
print(start_frame)
print(end_frame)
see MXS Help:
getTimeRange <controller> [#selOnly] [#allKeys] [#children]
Returns a time Interval value specifying the range of time covered by keys in the controller. The optional symbolic arguments specify options:
#selOnly : return the time range covered by the currently selected keys (in the track view)
#allKeys (default): the time range for all keys in the controller
#children : descends into sub-controllers and returns the total time interval covering all keys in all sub-controllers
so you need to ask about the range the node’s controller and its children (use optional param #children)
Yeah I saw this, I was struggling with the controller part, I’ve not used this part of maxscript in pymxs yet and was struggling to convert it over. Is the controller just the selected node or does it need to be a specific controller? Also will this matter if the keys are on position, rotation, scale etc.?
if you ask for a range of some controller without specifying #children this controller must to support keys… in general only leaf controllers support keys.
there is another way to get the range:
<controller>.keys[1].time
<controller>.keys[<controller>.keys.count].time
Theoretically the controller keys might not be sorted… you can sort them before getting the range. But in reality all the keys are usually sorted, unless you specifically shuffle them.
If you try to get the range of a prs controller, for example, with the #children option, the method returns the union of the pos, rot and scale controllers, taking in range all their subcontrollers (X, Y, Z).