2016-06-23 21 views
0

我对于为maya创建python工具感兴趣,我需要检测用户的点击输入,每次用户用鼠标左键单击时都会创建一个多维数据集。但问题是,我不知道该怎么做。我对python有很好的了解,但并不是那样的......使用python进行点击检测(对于maya 3D)

如果有人能帮助我,那将是美好的! 提前致谢!

+1

请先点击。这应该为你生成一个立方体 –

回答

1

你可以依靠draggerContext,如果你搜索足够有结果的每一个地方有关:)。但这里是最小的工作示例..

def createCubesForFun(): 
    x, y, z = tuple(cmds.draggerContext('cubeFunCtx', query=1, dragPoint=1)) 
    newBox = cmds.polyCube() 
    cmds.setAttr("%s.t" % newBox[0], x, y, z) 

cmds.draggerContext('cubeFunCtx', dragCommand='createCubesForFun()', space='world')  
cmds.setToolTo('cubeFunCtx') 
0

我认为你可以去PyQt的。检测一些焦点小部件。然后点击,找到无论选择什么

import sip 
import maya.cmds as cmds 
import maya.OpenMayaUI as apiUI 
from PyQt4 import QtGui, QtCore 


def getMayaWindow(): 
    """Get the maya main window as a QMainWindow instance""" 
    ptr = apiUI.MQtUtil.mainWindow() 
    return sip.wrapinstance(long(ptr), QtCore.QObject) 


def getFocusWidget(): 
    """Get the currently focused widget""" 
    return QtGui.qApp.focusWidget() 


def getWidgetAtMouse(): 
    """Get the widget under the mouse""" 
    currentPos = QtGui.QCursor().pos() 
    widget = QtGui.qApp.widgetAt(currentPos) 
    return widget 

# This is the syntax to find the right click button 
# QtGui.qApp.mouseButtons() & QtCore.Qt.RightButton