【问题标题】:How to create Maya sliders to move objects in interface如何创建 Maya 滑块以在界面中移动对象
【发布时间】:2017-04-06 12:36:38
【问题描述】:

我正在尝试使用滑块沿 x、y 和 z 轴移动对象。到目前为止,这是我的代码:

import maya.cmds as cmds

cmds.columnLayout( adjustableColumn=True )                                                

cmds.intSlider(min=-100, max=100, value=0, step=1, dc = cmds.move(x=True))

cmds.showWindow()

我一直收到这个错误

# Error: line 1: TypeError: file <maya console> line 10: Invalid arguments for flag 'dc'.  Expected string or function, got NoneType # 

我对 Python 很陌生,所以我不确定这意味着什么。非常感谢,马丁

【问题讨论】:

    标签: python maya


    【解决方案1】:

    你必须创建一个包含 cmds.move() 的函数

    import maya.cmds as cmds
    from functools import partial
    
    # Create the function to move
    def moveXYZ(slider, *args, **kwargs):
        # slider is the name of the controller
        # *args is to avoid a maya default argument passed trhought functions
        # **kwargs is used to pass maya flags to the function in order to chose X, Y or Z axis
    
        # the slider value is queried each time in order to refresh the value
        value = getSliderValue(slider)
        cmds.move(value, **kwargs)
    
    # slider get value, can fit any slider if you provide the name
    def getSliderValue(ctrlName):
        value = cmds.intSlider(ctrlName, q=True, value=True)
        return value
    
    #basic window
    cmds.window()    
    cmds.columnLayout( adjustableColumn=True )                                                
    # create the slider with a placeholder function
    mySlider = cmds.intSlider(min=-100, max=100, value=0, step=1, dc = 'empty')
    # now that the var mySlider is created, we can pass it as argument for our function
    # let's edit the function with functools.partial that allow us to pass some arguments to a function
    # Here we pass moveXYZ function then mySlider, the name of the X slider then x=1 to pass the flag to cmds.move(x=1)
    cmds.intSlider(mySlider, e=True, dc = partial(moveXYZ, mySlider, x=1))
    
    #redo it for all sliders
    # mySlider should be a dictionnary or at least a global, i.e :
    # uiDic = {}
    # uiDic['xslider'] = cmds.intSlider(min=-100, max=100, value=0, step=1, dc = 'empty')
    # cmds.intSlider(uiDic['xslider'], e=True, dc = partial(moveXYZ, uiDic['xslider'], x=1))
    
    cmds.showWindow()
    

    我可以解释任何你不明白的部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 1970-01-01
      • 2021-08-27
      相关资源
      最近更新 更多