PDA

View Full Version : swapping radio buttons for a slider


gunner89
11-23-2010, 06:06 PM
Hi, i have a piece of code that creates a basic user interface in python. I have the visibility being toggled via radio buttons but really want to be able to have a slider switch to control it, so slide left for on, right for off. I would also like to be able to display the x,y,z co ordinates of each object next to the on off slider. Any help would be greatly appreciated. Thanks

p, li { white-space: pre-wrap; } import maya.cmds as cmds
def window():
a=-1
if cmds.window("basicWindow", ex=True):
cmds.deleteUI("basicWindow")
cmds.window("basicWindow",w=400, h=500,t="Objects, Cameras and Lights")
cmds.rowColumnLayout(numberOfColumns=4, columnWidth=([1,100],[2,50],[3,55],[4,55]) )
cmds.radioCollection()
objectType = cmds.ls(s=True)
objectName = cmds.ls(tr=True)
for b in objectType:
a=a+1
cmds.button(l=b,c="cmds.select('"+b+"')")
cmds.text(l=cmds.objectType(b))
cmds.radioButton(l="vis ON",onc="cmds.setAttr('"+b+".v',1)")
cmds.radioButton(l="vis OFF",onc="cmds.setAttr('"+b+".v',0)")
cmds.button(l="refresh",c="cmds.refresh('basicWindow')")
cmds.showWindow()

window()

NaughtyNathan
11-23-2010, 08:46 PM
you want a slider for on/off? surely a checkBox is more appropriate?

:nathaN

gunner89
11-23-2010, 08:53 PM
i agree it would be more appropriate but ive been asked to show how to do it using a slider. I have included my more recent code after playing around with it, but can only get it to hide when sliding it, and it doesnt show it again when i slide it back, thanks.

p, li { white-space: pre-wrap; } import maya.cmds as cmds
def window():
a=-1
if cmds.window("basicWindow", ex=True):
cmds.deleteUI("basicWindow")
cmds.window("basicWindow",w=400, h=500,bgc=(1, 1, 1),t="Objects, Cameras and Lights")
cmds.rowColumnLayout(numberOfColumns=5, columnWidth=([1,100],[2,50],[3,55],[4,55],[4,55]) )
cmds.radioCollection()
objectType = cmds.ls(s=True) #Declares that the
objectName = cmds.ls(tr=True) #Declares that the transfer nodes are in the variable "objectName"
for b in objectType:
a=a+1
cmds.button(l=b,bgc=(1, 0.6, 0.2),annotation="Press to select",c="cmds.select('"+b+"')") #Creates the buttons for the nodes
cmds.text(l=cmds.objectType(b)) #Displays what type of object each node is, ie camera, light, shape.
cmds.radioButton(l="Show",onc="cmds.setAttr('"+b+".v',1)") #Checkbox to toggle vis on
cmds.radioButton(l="Hide",onc="cmds.setAttr('"+b+".v',0)")
cmds.floatSliderGrp( label='/Hide', field=True, minValue=0,maxValue=1,dc="cmds.setAttr('"+b+".v',0)")
cmds.button(l="Refresh",c="cmds.refresh(window())") #Refresh button to accomadate any added nodes in the scene
cmds.showWindow()

window()

NaughtyNathan
11-23-2010, 09:10 PM
yeah, your slider dragCommand is hard-coded to set the .v attribute to 0 no matter what, so it can only ever hide the object. Rather than set the value to 0 you need to set it to the slider value. This is unfortunately a lot more complex in basic Maya python than it should be, especially in this case as you are generating the controls in a loop. My advice would be to NOT use a slider for this, use attrControlGrp! ;) but I see that may not be viable for you here. take a look at this and see if it helps, rather than me try to poorly re-explain the gist of it:

http://www.luma-pictures.com/tools/pymel/docs/1.0/ui.html

(incidentally, I would use an intSlider rather than a float one!!)

:nathaN

gunner89
11-23-2010, 10:02 PM
thanks for your help. much appreciated

CGTalk Moderation
11-23-2010, 10:02 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.