Python Script to create objects from intSlider

Python Script to create objects from intSlider

strubefabian4
Contributor Contributor
995 Views
1 Reply
Message 1 of 2

Python Script to create objects from intSlider

strubefabian4
Contributor
Contributor

Hey guys, 
i am very new to python and want to create a Script to create joints.

The Idea is to get a window and there I can set the number with the intSlider.
Once i press CreateJoints it should create the number i set in the intSlider:

I just can't figer out what's wrong here:

import maya.cmds as cmds
cmds.window(title = "Create Joints", width = 300, height = 100)
cmds.columnLayout("CreateJointsLayout", adjustableColumn = True)
slider = cmds.intSliderGrp ( "CreateJoints", label = "Joints", field = True, fieldMinValue = 1, fieldMaxValue = 10, minValue = 1, maxValue = 100, columnWidth3 = [50, 50, 50], columnAlign3 = ["left", "both", "left"], value = 0, parent = "CreateJointsLayout")
cmds.showWindow()
Number = cmds.intSliderGrp ( "CreateJoints", query = True, value = True)
CreateOne = cmds.button(label = "click me", parent = "CreateJointsLayout", command = CreateJoints)
print Number

def CreateJoints():
for Number in slider:
sel = cmds.joint( p=(0, 0, 0) )
cmds.select( sel, tgl=True )

Thanks for your help and time!

0 Likes
996 Views
1 Reply
Reply (1)
Message 2 of 2

kevin.picott
Alumni
Alumni

There are a few things going on here, I'll tell you what they are and then show a finished example.

 

  1. The intSliderGrp "command" argument needs to refer to a known Python method, so you have to move the definition of CreateJoints before it
  2. In order to iterate over your new value you have to query it from the intSliderGrp.
  3. The CreateJoints callback from a button requires a single argument, which can be ignored for your purposes
  4. Your "for" loop should iterate over a numeric range. "slider" is a UI widget
import maya.cmds as cmds

cmds.window(title = "Create Joints", width = 300, height = 100)
cmds.columnLayout("CreateJointsLayout", adjustableColumn = True)
slider = cmds.intSliderGrp ( "CreateJoints", label = "Joints", field = True, fieldMinValue = 1, fieldMaxValue = 10, minValue = 1, maxValue = 100, columnWidth3 = [50, 50, 50], columnAlign3 = ["left", "both", "left"], value = 0, parent = "CreateJointsLayout")
cmds.showWindow()

def CreateJoints(button_value):
    slider_value = cmds.intSliderGrp( slider, query=True, value=True )
    print slider_value
    for Number in range(0,slider_value):
        sel = cmds.joint( p=(0, 0, 0) )
        cmds.select( sel, tgl=True )
        
CreateOne = cmds.button(label = "click me", parent = "CreateJointsLayout", command = CreateJoints)

Hope that leads you in the right direction...



Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes