如何创建Maya滑块以在界面中移动对象 [英] How to create Maya sliders to move objects in interface

查看:183
本文介绍了如何创建Maya滑块以在界面中移动对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use sliders to move objects along the x,y and z axis. This is my code so far:

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很陌生,所以我不确定它的含义.非常感谢,马丁(Martyn)

I am very new to Python so I am not sure what it means. Many Thanks, Martyn

推荐答案

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

you have to create a function containing 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()

我可以解释您不理解的任何部分

I can explain any part you would not understand

这篇关于如何创建Maya滑块以在界面中移动对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆