views:

68

answers:

1

I need to call a function ( Maya-Python ) based on cube rotationX. For that I have to capture the event, programmatically.

I tried using while loop but It stucks in the loop, Nothing can be done in that time. I tried theading (python), still same.

Can it be done this or other way? If yes, How?

Maya 2009 in Windows XP

Some failed code references:

import maya.cmds as cmds    
while (count < 90):
     lock = cmds.getAttr('pCube1.rotateX',lock=False)
     print lock
     count = count + 1 

Here Python wise:

#!/usr/bin/python

    import thread
    import time

# Define a function for the thread
def cubeRotateX( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
try:
   thread.start_new_thread( cubeRotateX, ("Thread-1", 2, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass
A: 

It sounds like a scriptJob may be what you're after. Here's a simple example below. However, in this example the callback will only be called when you release the mouse from rotating.

import maya.cmds

def myRotateCallback():
    print 'do something'

maya.cmds.scriptJob( attributeChange=['pCube1.rotateX', myRotateCallback] )

If you want to receive continuous callbacks while rotating the cube, you can do that at the maya API level with MNodeMessage::addNodeDirtyPlugCallback.

kb
Thanks, I'll work on it (on Saturday(21 April'10)).
Rahul2047
Worked Nicely .. is there some tutorial for these kind of activities. (If it is there in Maya Docs then its ok.)
Rahul2047