【发布时间】:2016-10-26 09:37:39
【问题描述】:
我对为maya制作python工具很感兴趣,我需要检测用户的点击输入,基本上是在用户每次用鼠标左键点击时创建一个立方体。但问题是我不知道该怎么做.. 我对 python 有很好的了解,但不知道...
如果有人可以帮助我,那就太好了! 提前致谢!
【问题讨论】:
-
尝试先点击。那应该为你生成一个立方体
标签: python click detection maya autodesk
我对为maya制作python工具很感兴趣,我需要检测用户的点击输入,基本上是在用户每次用鼠标左键点击时创建一个立方体。但问题是我不知道该怎么做.. 我对 python 有很好的了解,但不知道...
如果有人可以帮助我,那就太好了! 提前致谢!
【问题讨论】:
标签: python click detection maya autodesk
您可以依赖 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')
【讨论】:
我认为你可以使用 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
【讨论】: