So this is annoying but I think this has something to do with how
findKeyframe works.

If you add a pause it seems to work just fine:

import maya.cmds as mc

#create sphere

mc.polySphere(ch=True,o=True, r=5)

#key sphere in diffrent time

mc.currentTime(5, edit=True )

mc.setKeyframe("pSphere1")

mc.currentTime(10, edit=True )

mc.setAttr("pSphere1.translateY", 5)

mc.setKeyframe("pSphere1")

mc.currentTime(0, edit=True )


#Not sure why this fixes it technically - but it seems to have removed it
for myself.

import time

time.sleep(1) #.4 was actually the smallest value that seemed to reliably
get the correct result


#getting first and last key

firstKey = mc.findKeyframe(timeSlider=True, which='first')

lastKey = mc.findKeyframe(timeSlider=True, which='last')

print firstKey

print lastKey


Of interesting note this didn't fix it without the pause and I'm not sure
why:

import maya.utils

firstKey = maya.utils.executeInMainThreadWithResult(
mc.findKeyframe,timeSlider=True, which='first')

lastKey = maya.utils.executeInMainThreadWithResult(
mc.findKeyframe,timeSlider=True, which='last')


Ian


On Fri, Feb 25, 2011 at 5:39 PM, Ctorres <[email protected]> wrote:

> Hey all,
> For some reason I can't get this code to work correctly.Please help.
> I'm working out of Maya 2009. So when I run this python code I get the
> values for the firstKey and lastKey as 0 but if  I just run the last 4
> lines of code. I will get something different now,  firstKey=5 and
> lastKey=10. I'm not sure what is happening here. I guess my ultimate
> goal is to find out what is the first keyframe and lastkeyframe of any
> maya scene and be able to set a piece of code in the end like this
> ------ mc.playbackOptions(aet=lastKey, ast=firstKey)
>
> Thanks Again,
> Chris
>
> --------Start New Scene----------
>
> import maya.cmds as mc
> #create sphere
> mc.polySphere(ch=True,o=True, r=5)
>
> #key sphere in diffrent time
> mc.currentTime(5, edit=True )
> mc.setKeyframe("pSphere1")
> mc.currentTime(10, edit=True )
> mc.setAttr("pSphere1.translateY", 5)
> mc.setKeyframe("pSphere1")
> mc.currentTime(0, edit=True )
>
> #getting first and last key
> firstKey = mc.findKeyframe(timeSlider=True, which='first')
> lastKey = mc.findKeyframe(timeSlider=True, which='last')
> print firstKey
> print lastKey
>
> --
> http://groups.google.com/group/python_inside_maya
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to