不明白为什么这个Maya UI代码不起作用

时间:2019-07-15 04:46:59

标签: python user-interface maya

尝试在maya中创建自定义UI来管理IKFK切换。经过一些实验,我设法以视觉方式获得界面。由于某种原因,在为准备添加按钮功能的准备中添加了一些代码之后,运行脚本不再打开我的UI。我不确定为什么代码无法正常运行,因为运行时什么也没发生。

import maya.cmds as cmds

def ui():
    if cmds.window('IK_FK_controller', exists = True):
        cmds.deleteUI('IK_FK_controller')


    myWin = cmds.window('IK_FK_controller', wh=[100,200], resizeToFitChildren=True)

    cmds.columnLayout(columnAttach=('both', 5), columnWidth=200)

    cmds.text(label = 'FK IK Switch', align ='center')
    cmds.separator(h=5)
    cmds.text(label = 'Left Arm', align ='center')
    cmds.separator(h=5, style = 'none')

    cmds.rowLayout(numberOfColumns=2, columnWidth2=(90, 80))

    cmds.button(label='IK', command = IKswitch, width=75)
    cmds.button(label='FK', command = FKswitch, width=75)

    cmds.setParent('..')

    cmds.rowLayout(numberOfColumns=2, columnWidth2=(90, 80))

    cmds.button(label='FK 2 IK', command = Fk2Ik, width=75)
    cmds.button(label='IK 2 FK',  command = Ik2Fk, width=75)
    cmds.setParent('..')
    cmds.separator(h=5, style = 'none')
    cmds.separator(h=5)

    cmds.text(label = 'Right Arm', align ='center')
    cmds.separator(h=5, style = 'none')

    cmds.rowLayout(numberOfColumns=2, columnWidth2=(90, 80))

    cmds.button(label='IK', command = IKswitch, width=75)
    cmds.button(label='FK', command = FKswitch, width=75)

    cmds.setParent('..')

    cmds.rowLayout(numberOfColumns=2, columnWidth2=(90, 80))

    cmds.button(label='FK 2 IK', command = Fk2Ik, width=75)
    cmds.button(label='IK 2 FK', command = Ik2Fk, width=75)

    cmds.setParent('..')
    cmds.separator(h=5, style = 'none')

    cmds.showWindow('IK_FK_controller')


def  FKswitch():
    print ('In FK mode')

def IKswitch():
    print('In IK mode')

def Fk2Ik():
    print('Fk snapped to IK')

def Ik2Fk():
    print('IK snapped to FK')

1 个答案:

答案 0 :(得分:0)

想通了。

应该在ui def的末尾添加ui()