在maya UI中调用用户输入值

时间:2016-05-05 02:12:14

标签: python maya

我在maya中使用python构建了一个小程序,我对打印用户在点击“Apply”时输入的值感兴趣。有关如何实现这一目标的任何想法?然后我想使用另一段代码中的值在maya中创建建筑物。

def runGrid():
if mc.window('windowTest9', ex=True):
    mc.deleteUI('windowTest9', window=True)

mc.window('windowTest9', title='BuilGen', sizeable=False, resizeToFitChildren=True)

mc.rowColumnLayout( numberOfColumns = 2, columnWidth = [ (1, 150), (2, 100), (3, 75)])  

#mc.text( label = 'Top Bar')
mc.separator( h = 10, style = 'none')
mc.separator( h = 10, style = 'none')

mc.text(label='Create a New Building', align = 'left')
mc.image(image='F:\Photos\office-building-icon-687152.png')


# insert a blank line space
mc.separator( h = 10, style = 'singleDash')
mc.separator( h = 10, style = 'singleDash')


mc.text( label = 'number of sections wide:', align = 'left')
buildingWidth = mc.intField( value = 4)


mc.text( label = 'number of sections deep:', align = 'left')
buildingDepth = mc.intField( value = 3)    

mc.text( label = 'number of floors:', align = 'left')
numberOfFloors = mc.intField( value = 2)    


mc.text( label = 'roof:', align = 'left')
numberOfFloors = mc.checkBox (label='Y/N')    
mc.separator( h = 10, style = 'none')

# insert another blank line
mc.separator( h = 10, style = 'none')
mc.separator( h = 10, style = 'none')


# create the buttons
mc.separator( h = 10, style = 'none')
mc.button( label = 'Apply', command = '' )


mc.button( label = 'Cancel', command = 'mc.deleteUI("windowTest9", window=True)')

mc.showWindow()

runGrid()

2 个答案:

答案 0 :(得分:1)

编辑:像DrWeeny说的那样,最好参考其他类似主题。

我前段时间在博客上做了一点提醒,能够测试所有不同的本机Maya UI使用命令的方式,并快速测试它们:

  • 经典玛雅字符串
  • 作为参数
  • 拉姆达
  • functools.partial
  • pymel.core.Callback

每个案例都给出了将变量作为参数传递给这些函数的示例。因为有时你必须能够。 总的来说,我完全推荐使用 functools.partial ,它只提供优于其他的优势(如果你忘了PySide)。

Maya UI types

CKQuery

使用班级时

因为它不是在考虑课堂的情况下制作的,所以当你在课堂上时,某些方法根本不起作用。

CKQuery

答案 1 :(得分:0)

您可以在其他帖子上查看答案:Printing the label of a button when clicked或此处使用词典:Maya Python - Using data from UI

from functools import partial

def queryInputs(*args):
    #args0 = label01
    print(cmds.text(args[0], q=True, label = 1))
    #args[1] = int_01
    print(cmds.intField(args[1], q=True, v = 1))
    #args[2] = cb_01
    print(cmds.checkBox(args[2], q=True, v = 1))


def runGrid():
    if cmds.window('windowTest9', ex=True):
        cmds.deleteUI('windowTest9', window=True)

    cmds.window('windowTest9', title='BuilGen', sizeable=False, resizeToFitChildren=True)

    cmds.rowColumnLayout( numberOfColumns = 2, columnWidth = [ (1, 150), (2, 100), (3, 75)])  

    label_01 = cmds.text( label = 'number of sections wide:', align = 'left')
    int_01 = buildingWidth = cmds.intField( value = 4)

    cb_01 = numberOfFloors = cmds.checkBox (label='Y/N')    

    cmds.button( label = 'Apply', command = partial(queryInputs, label_01, int_01, cb_01) )

    cmds.button( label = 'Cancel', command = 'cmds.deleteUI("windowTest9", window=True)')

    cmds.showWindow()

runGrid()