#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
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')
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 )
mc.refresh()
#getting first and last key
firstKey = mc.findKeyframe(timeSlider=True, which='first')
lastKey = mc.findKeyframe(timeSlider=True, which='last')
print firstKey
print lastKey
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
Not sure why though.