On Wed, Mar 2, 2011 at 8:28 PM, Ian Jones <[email protected]> wrote:

> 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
>
>
>
Out of curiosity, I gave maya.utils.processIdleEvents() and mc.refresh() a
shot, and those both seemed to do the trick.  Though I was testing in gui
mode, and sometimes those don't work so hot in batch mode... so you might
want to test that if you need it there.


> #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')
>
>
>
According to the docstring for executeInMainThreadWithResult, if you're
already in the main thread, this essentially doesn't do anything... were you
thinking of maya.utils.executeDeferred? Of course, then you'd have to find
some way to get the result back...

- Paul


> 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
>

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

Reply via email to