在MAYA 2009中,是否可以捕获立方体旋转事件?

发布于 2024-08-29 17:06:27 字数 773 浏览 9 评论 0原文

我需要调用一个基于立方体旋转X的函数(Maya-Python)。为此,我必须以编程方式捕获事件。

我尝试使用 while 循环,但它卡在循环中,当时什么也做不了。 我尝试了 theading (python),仍然一样。

可以这样或其他方式完成吗?如果是,如何?

Windows XP 中的 Maya 2009

一些失败的代码参考:

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

这里是 Python 明智的:

#!/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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画▽骨i 2024-09-05 17:06:27

听起来 scriptJob 可能就是您想要的。下面是一个简单的例子。但是,在此示例中,仅当您释放鼠标以使其不再旋转时才会调用回调。

import maya.cmds

def myRotateCallback():
    print 'do something'

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

如果要在旋转立方体时接收连续回调,可以在 Maya API 级别使用 MNodeMessage::addNodeDirtyPlugCallback 来实现。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文