0

In this code, I have an object creation menu that takes in values from a slider and uses that in the creation of the primitive - How can I actually get the sliders to store the number displayed as right now it just does nothing.

I could remove the sliders but ideally, id like to have them for a nicer user interface

import maya.cmds as mt

def ShowUI():

    if mt.window("Main", exists = True):
        mt.deleteUI("Main")

    mt.window("Main", title = "Maya Primitives", w = 300, h = 500)
    mt.columnLayout("MainLayout", w = 300, h =500)
    mt.optionMenu("PolygonMenu", w = 250, label = "Polygon Selection:")
    mt.menuItem(label = "Sphere")
    mt.menuItem(label = "Cube")
    mt.menuItem(label = "Cylinder")
    mt.button("Create", label = "Create", w = 300, command=ObjectCreation)
    mt.button("Delete", label = "Delete", w = 300, command=DeleteButton)
    mt.button("Clear", label = "Clear", w = 300, command=SceneClear)
    mt.showWindow("Main")

def DeleteButton(*args):
    mt.delete()

def SceneClear(*args):
    mt.delete(all=True, c=True)


def ObjectCreation(*args):
    currentValue = mt.optionMenu("PolygonMenu", query=True, value=True)
    if currentValue == "Sphere":
        SphereSlider()
        SphereRadius = mt.intSliderGrp(Sphradius, q = True, Value=True)
        finalSphere= mt.polySphere(r=SphereRadius, name = "Sphere", ch=False)


    elif currentValue == "Cube":
        CubeSlider()
        CubeWidth = mt.intSliderGrp(CubeW, q = True, Value=True)
        CubeHeight = mt.intSliderGrp(CubeH, q = True, Value=True)
        CubeDepth = mt.intSliderGrp(CubeD, q = True, Value=True)
        finalSphere= mt.polyCube(w=CubeWidth, h=CubeHeight, d=CubeDepth, name = "Cube", ch=False)        


    elif currentValue == "Cylinder":
        CylinderSlider()
        CyclinderRadius =  mt.intSliderGrp(Cylradius, q = True, Value=True)
        CyclinderHeight =  mt.intSliderGrp(CylH, q = True, Value=True)
        finalCylinder= mt.polyCylinder(r=CylinderRadius, h=CylinderHeight, name = "Cylinder", ch=False)


def SphereSlider():
    Sphradius = mt.intSliderGrp(l="Radius",min=0,max=25, field=True)

def CubeSlider():
    CubeW = mt.intSliderGrp(l="Width", min=0, max=25, field=True)
    CubeH = mt.intSliderGrp(l="Height", min=0, max=25, field=True)
    CubeD = mt.intSliderGrp(l="Depth", min=0, max=25, field=True)

def CylinderSlider():
    Cylradius = mt.intSliderGrp(l="Radius",min=0,max=25, field=True)
    CylH = mt.intSliderGrp(l="Height", min=0, max=25, field=True)


ShowUI()

1 Answers1

0

okay so to create a slider you use this command :

sphere_slider = mt.intSliderGrp(l="Radius",min=0,max=25, field=True)

to query it :

slider_value = mt.intSliderGrp(sphere_slider , q = True, Value=True)

but because you have those in two different def, you need to pass the name of the slider between them. - For this you can make sphere_slider a global. - Second option, you can give a unique name to your control (a bit dangerous because maya oculd rename it) :

mt.intSliderGrp("sphere_slider_name", l="Radius",min=0,max=25, field=True)
slider_value = mt.intSliderGrp("sphere_slider_name", q = True, Value=True)

-third option, you can use dictionnaries or even classes : .Maya Python - Using data from UI .Using Sliders in Maya with Python to control Shapes - intSliderGrp .How to create Maya sliders to move objects in interface

DrWeeny
  • 2,487
  • 1
  • 14
  • 17