Hello,
I wrote a script that's supposed to autamically set keyframes during playback by mouse click and release. The problem is that when i hold the mouse maya doesn't update and when the release command is called the currenttime query returns the same value as for the click (even though the time continued to run forward in the background).
Maybe there's a better way to do this?
Well. here's the script:
(arrg, this weird code editor only returns white on white and I can't delete it)
import maya.cmds as mc
def liveanim_ctx_click():
sel = mc.ls(selection = True)
if mc.attributeQuery('anim', n = sel[0], exists = True)==False:
mc.addAttr(at = 'double', ln = 'anim', keyable = True, minValue = 0, maxValue=100)
ctime = mc.currentTime(query=True)
if mc.play( q=True, state=True ) == True:
mc.setKeyframe(time = ctime-1, value = 0, attribute = 'anim')
mc.setKeyframe(time = ctime, value = 100, attribute = 'anim')
print 'click1'
def liveanim_ctx_release():
if mc.play( q=True, state=True ) == True:
ctime = mc.currentTime(query=True)
mc.setKeyframe(time = ctime+1, value = 0, attribute = 'anim')
print 'release'
def set_liveanim_ctx():
if mc.draggerContext('liveanim_ctx',ex = True) == True:
mc.draggerContext('liveanim_ctx', edit=True, space='world', pressCommand='liveanim_ctx_click()', releaseCommand='liveanim_ctx_release()',cursor='hand')
if mc.draggerContext('liveanim\_ctx',ex = True) == False:
mc.draggerContext( 'liveanim\_ctx',space='world', pressCommand='liveanim\_ctx\_click()',releaseCommand='liveanim\_ctx\_release()',cursor='hand')
mc.setToolTo('liveanim\_ctx')