在maya UI中调用用户输入值

2024-09-29 05:29:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我在maya中使用python构建了一个小程序,我对打印用户单击“应用”时输入的值感兴趣。有什么办法让我做到这一点吗?然后我想使用另一段代码中的值在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()

Tags: oftextnonetruenumbervaluestylemc
2条回答

编辑:正如Weeny博士所说,最好参考其他类似的主题。


前段时间,我在我的博客上做了一个小小的提醒,为了能够测试所有不同的本地Maya UI命令使用方式,以及一种快速测试方法:

  • 经典maya字符串
  • 函数作为参数
  • 兰姆达
  • functools.partial
  • 在PyCore.回调在

每种情况下还提供了将变量作为参数传递给这些函数的示例。因为有时候你必须有能力。 总的来说,我完全推荐使用functools.partial,它只提供了比其他的优势(如果您忘记了PySide)。在

Maya UI types

def function(*args):
    print args
    cmds.textFieldGrp(text, edit=True, text=str(args))

variable = 'Variable'
width = [1, 250]
align = [1, 'left']
window = cmds.window(title='UI and commands arguments.')
cmds.columnLayout()

cmds.textFieldGrp(label="\"function()\"", changeCommand="function()", columnWidth=width, columnAlign=align)
cmds.textFieldGrp(label="function", changeCommand=function, columnWidth=width, columnAlign=align)
cmds.textFieldGrp(label="\"function(variable)\"", changeCommand="function(variable)", columnWidth=width, columnAlign=align)
cmds.textFieldGrp(label="lambda x: function(variable)", changeCommand=lambda x: function(variable), columnWidth=width, columnAlign=align)
cmds.separator(style="double", height=20)

import functools
cmds.textFieldGrp(changeCommand=functools.partial(function), label='functools.partial(function)', columnWidth=width, columnAlign=align)
cmds.textFieldGrp(changeCommand=functools.partial(function, variable), label='functools.partial(function, variable)', columnWidth=width, columnAlign=align)
cmds.separator(style="single", height=20)

import pymel.core
cmds.textFieldGrp(changeCommand=pymel.core.Callback(function), label='pymel.core.Callback(function)', columnWidth=width, columnAlign=align)
cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(function), label='pymel.core.CallbackWithArgs(function)', columnWidth=width, columnAlign=align)
cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(function, variable), label='pymel.core.CallbackWithArgs(function, variable)', columnWidth=width, columnAlign=align)

cmds.separator(style="single", height=20)
text = cmds.textFieldGrp(label='RESULT: ', text='', width=500)
cmds.showWindow()

使用类时

因为它并不是为了使用类,所以当你在一个类中时,有些方法根本不起作用。在

^{pr2}$

你可以在另一篇文章中看到答案: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()

相关问题 更多 >