使用Python在Maya中使用形状滑块 [英] Using Sliders for shapes in Maya with Python

查看:177
本文介绍了使用Python在Maya中使用形状滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,我有以下代码,我正在尝试对ColourTranslateRotateScale使用以下滑块来实现此代码中的形状.

I'm new to Python and I have the following code, I am trying to use the following sliders for the Colour, Translate, Rotate and Scale for the shapes I have in this code.

是否可以使用这些滑块控制所有形状?我似乎无法弄清楚我已经尽力了.

Is there a way I can control all the shapes with these sliders? I can't seem to figure it out I've tried everything that I could.

任何帮助将不胜感激,谢谢.

Any help would be appreciated, thank you.

#Importing all Maya commands to Python
import maya.cmds as cmds
from functools import partial

class CreateUI():
    def __init__(self):
        windowID = "myWindowID"

        if cmds.window(windowID, exists=True):
            cmds.deleteUI(windowID)

#-----------------------------------------------Layout of Interface 

        masterWindow = cmds.window(windowID, title="User Interface", w=500, h=800, sizeable=False, resizeToFitChildren=True)
        ShapeLayout = cmds.rowColumnLayout(parent=masterWindow, numberOfColumns=1, columnOffset=[(2,"left",0)])



#-----------------------------------------------Shape Functions       

#Functions for creating shapes        
        def mySphere(*args):
            cmds.polySphere()

        def myCube(*args):
            cmds.polyCube()

        def myCylinder(*args):
            cmds.polyCylinder()

        def myCone(*args):
            cmds.polyCone()

        def myTorus(*args):
            cmds.polyTorus()

        def myPlane(*args):
            cmds.polyPlane()

        def myDelete(*args):
            cmds.select()
            cmds.delete()

#Gets rid of any shapes in the scene so that the user doesn't have to every time the UI is launched or the sript is run
        ShapeList = cmds.ls("mySphere*", "myCube*", "myCylinder*", "myCone*", "myTorus*", "myPlane*","pSphere*", "pCube*", "pCylinder*", "pCone*", "pTorus*", "pPlane*")
        if len(ShapeList)>0:
            cmds.delete(ShapeList)

#-----------------------------------------------Shape Buttons         

#Buttons for creating shapes    
        cmds.button(label="Sphere", command=mySphere)
        cmds.button(label="Cube", command=myCube)
        cmds.button(label="Cylinder", command=myCylinder)
        cmds.button(label="Cone", command=myCone)
        cmds.button(label="Torus", command=myTorus)
        cmds.button(label="Plane", command=myPlane)
        cmds.button(label="Delete", command=myDelete)

        #COLOUR
        cmds.separator(h=20, style="none")
        cmds.colorSliderGrp('blockColour',label="Colour", hsv=(120, 1, 1))
        cmds.separator(h=20, style="none")

        #TRANSLATE
        TranslateX = cmds.intSliderGrp('TX',label="Translate X ", field=True, min=1, max=100, value=0)  
        TranslateY = cmds.intSliderGrp('TY',label="Translate Y ", field=True, min=1, max=100, value=0)
        TranslateZ = cmds.intSliderGrp('TZ',label="Translate Z ", field=True, min=1, max=100, value=0)
        cmds.separator(h=20, style="none")

        #ROTATE
        RotateX = cmds.intSliderGrp('RX',label="Rotate X ", field=True, min=1, max=100, value=0)  
        RotateY = cmds.intSliderGrp('RY',label="Rotate Y ", field=True, min=1, max=100, value=0)
        RotateZ = cmds.intSliderGrp('RZ',label="Rotate Z ", field=True, min=1, max=100, value=0)
        cmds.separator(h=20, style="none")

        #SCALE
        ScaleX = cmds.intSliderGrp('SX',label="Scale X ", field=True, min=1, max=100, value=0)  
        ScaleY = cmds.intSliderGrp('SY',label="Scale Y ", field=True, min=1, max=100, value=0)
        ScaleZ = cmds.intSliderGrp('SZ',label="Scale Z ", field=True, min=1, max=100, value=0)



        cmds.showWindow(windowID)
ui=CreateUI()        

推荐答案

看看您的其他帖子,重复帖子将不会给您带来更多的可见性

look at your other post, duplicating a post won't give you more visibilty

这篇关于使用Python在Maya中使用形状滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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