问题
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()
回答1:
look at your other post, duplicating a post won't give you more visibilty
来源:https://stackoverflow.com/questions/50110785/using-sliders-for-shapes-in-maya-with-python