Getting intSliderGrp value from one function to another




I’m currently working on a rigging script that in the end will be able to create a joint chain based on values that the user can enter via sliders.

I’m having some trouble getting the values from the sliders into the function that creates the initial joint setup.

My code is below. What I want to do is to grab the values of the sliders and chuck them into the functions rbLegGhostJoints and rbArmGhostJoints, so that I can use those values when creating the “ghost” joints(e g spheres or some such). I don’t have much experience with Python to be honest, or not as much I’d like, and I’m having some trouble figuring out callbacks and whether or not I should use a class for this, and a bunch of other stuff I’m trying to learn.

import pymel.core as pm

def rbLegGhostJoints(*args):
def rbArmGhostJoints(*args):
def rbLegJoints(*args):
def rbArmJoints(*args):

def rbRiggingUI():		
	if pm.window( "rbRiggingWindow", exists = True ):
	    pm.deleteUI( "rbRiggingWindow" )
	pm.window( "rbRiggingWindow", title = "RB Rigging", resizeToFitChildren = True )
	tabControls = pm.tabLayout()
	legLayout = pm.columnLayout()
	legLengthText = pm.text( label = "Enter leg start length:" )
	legLength = pm.textField()
	legJointsText = pm.text( label = "Number of leg joints:" )
	numberOfLegJoints = pm.intSliderGrp( "numberOfLegJoints", minValue = 3, maxValue = 20, step = 1, field = True )
	legUpperTwistsText = pm.text( label = "Number of upper leg twist joints:" )
	numberOfUpperLegTwists = pm.intSliderGrp( "numberOfUpperLegTwists", minValue = 0, maxValue = 10, step = 1, field = True )
	legLowerTwistsText = pm.text( label = "Number of lower leg twist joints:" )
	numberOfLowerLegTwists = pm.intSliderGrp( "numberOfLowerLegTwists", minValue = 0, maxValue = 10, step = 1, field = True)
	createLegGhostJoints = pm.button( label = "Create ghost joints", command = rbLegGhostJoints )
	pm.separator( height = 20, width = 300)
	createLegJoints = pm.button( label = "Create joints", command = rbLegJoints )
	armLayout = pm.columnLayout()
	armLengthText = pm.text( label = "Enter arm start length:" )
	armLength = pm.textField()
	armJointsText = pm.text( label = "Number of arm joints:" )
	numberOfArmJoints = pm.intSliderGrp( "numberOfArmJoints", minValue = 3, maxValue = 20, step = 1, field = True )
	armUpperTwistsText = pm.text( label = "Number of upper arm twist joints:" )
	numberOfUpperArmTwists = pm.intSliderGrp( "numberOfUpperArmTwists", minValue = 0, maxValue = 10, step = 1, field = True )
	armLowerTwistsText = pm.text( label = "Number of lower arm twist joints:" )
	numberOfLowerArmTwists = pm.intSliderGrp( "numberOfLowerArmTwists", minValue = 0, maxValue = 10, step = 1, field = True )
	createArmGhostJoints = pm.button( label = "Create ghost joints", command = rbArmGhostJoints )
	pm.separator( height = 20, width = 300)
	createArmJoints = pm.button( label = "Create joints", command = rbArmJoints )
	pm.tabLayout( tabControls, edit = True, tabLabel=(( legLayout, "Legs" ),( armLayout, "Arms" )) )
	pm.showWindow( "rbRiggingWindow" )


Not pymel specific, but this post has several different options for how to structure this kind of code:

A class is a good way to go if the relationships between different pieces are complex. If you’re basically collecting information and then creating a ‘go’ button, you can do that by nesting the button function inside the function that creates the gui – see the article above and read the bit about ‘closures’ to see how and why that works.

Alternately, If you are just checking the sliders, you can create a function that returns little functions which only get the values of a gui widget. Instead of creating the widgets directly, you call your function and collect the results. Then you can use them to get the values like that. Here’s a simple example:

def value_slider(ui_label):
    slider = cmds.intSlider(ui_label)
    def query():
        return cmds.intSlider(slider, q=True, v=True)
    return slider, query
w = cmds.window()
c = cmds.columnLayout()
s1, q1 = value_slider('slider1')
s2, q2 = value_slider('slider2')


# play with the sliders a bit
q1()  # will print the slider value for the first slider
q2()  # etc

Lastly if you are just getting started with maya GUI you might want to try mGui, which is a python library for making Maya gui easier to work with. Follow the link for more details.


There is a neat way of calling back too, if it’s not too complicated a script.

intSlider -cc ( “someProc #1”);

global proc someProc(int $valueFromSlider){