【发布时间】:2014-05-05 22:40:27
【问题描述】:
我有一个我在 python 中为 maya 编写的脚本,有 3 个标记为 X Y Z 的按钮。根据按下的按钮,我想要一个变量将特定值传递给函数。我怎样才能做到这一点??关于我想要传递的内容,我已经在按钮的 cmets 中写了。它似乎只是打印'假'我不知道为什么。
import maya.cmds as cmds
class createMyLayoutCls(object):
def __init__(self):
pass
def show(self):
self.createMyLayout()
def createMyLayout(self):
#check to see if our window exists
if cmds.window('utility', exists = True):
cmds.deleteUI('utility')
# create our window
self.window = cmds.window('utility', widthHeight = (200, 200), title = 'Distribute', resizeToFitChildren=1, sizeable = False)
cmds.setParent(menu=True)
# create a main layout
mainLayout = cmds.gridLayout( numberOfColumns=3, cellWidthHeight=(70, 50) )
# X Y Z BUTTONS
btnAlignX = cmds.button(label = 'X', width = 40, height = 40, c = self.TakeAction) # should pass 'axis='X"
btnAlignY = cmds.button(label = 'Y', width = 40, height = 40, c = self.TakeAction) # should pass 'axis='Y"
btnAlignZ = cmds.button(label = 'Z', width = 40, height = 40, c = self.TakeAction) # should pass 'axis='Z"
# show window
cmds.showWindow(self.window)
def TakeAction(self, axis=''):
print axis
if axis == 'x':
print 'you selected x'
if axis == 'y':
print 'you selected y'
if axis == 'y':
print 'you selected z'
b_cls = createMyLayoutCls()
b_cls.show()
【问题讨论】: