Jan 2016
1 / 3
Jan 2016
Oct 2017

Hi
I'm trying to create a script that automatically sets the timeline range to the animation range of a selected camera.
I track my cameras in nuke using DPXs sequences created from the original ARRIRAW files. so its animation range is based on the frame range of the clip.
So when i import the camera into maya, the animation doesnt start from 1, its whatever the frame range was so could be 19567-20111 for example.

I've been trying to create a python script using this as my base,

import maya.cmds as cmds
firstKey = cmds.keyframe("camera1.translateX", index=(0,0), query=True);
print firstKey

and i get
19567.0

and i know i can manually alter the animation start time using 

playbackOptions -ainmationStartTime 19567;

but when i try and patch one into the other im getting the error

Invalid arguments for flag 'ast'.  Expected time, got [ float ],

So how can i convert my returned float value, from the first command, into a time ( i assume as i could just type in 19567, all it actually needs is an integer, not a float.)

Thanks

Andy 

  • created

    Jan '16
  • last reply

    Oct '17
  • 2

    replies

  • 4.7k

    views

  • 3

    users

  • 1

    link

6 months later

You need to provide time in the format supported by the command flag. In this case, time is represented as an integer. To convert a float to an integer, use the builtin int() function. This rounds toward zero. If you wish to round the number instead, use the round() builtin.

>>> timeVar = 10.0
>>> timeVar = int(timeVar)
 
cmds.playbackOptions(ast=timeVar)
1 year later

Method int() is the Python standard built-in function to convert a string into an integer value. You call it with a string containing a number as the argument, and it returns the number converted to an actual integer....Python string to int33

Suggested Topics

Want to read more? Browse other topics in Maya or view latest topics.