swapping radio buttons for a slider

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 11 November 2010   #1
swapping radio buttons for a slider

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():
     if cmds.window("basicWindow", ex=True):
      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]) )
      objectType = cmds.ls(s=True)                                                             
     objectName = cmds.ls(tr=True)                                                          
      for b in objectType:
         cmds.radioButton(l="vis ON",onc="cmds.setAttr('"+b+".v',1)")                            
         cmds.radioButton(l="vis OFF",onc="cmds.setAttr('"+b+".v',0)")                           
Old 11 November 2010   #2
you want a slider for on/off? surely a checkBox is more appropriate?

Old 11 November 2010   #3
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():
     if cmds.window("basicWindow", ex=True):
      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]) )
      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:
         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.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
Old 11 November 2010   #4
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:


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

Old 11 November 2010   #5
thanks for your help. much appreciated
Old 11 November 2010   #6
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 09:40 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.