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 CLOSED
 
Thread Tools Search this Thread Display Modes
  11 November 2010
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():
     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()
 
 
  11 November 2010
you want a slider for on/off? surely a checkBox is more appropriate?

:nathaN
 
  11 November 2010
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()
 
  11 November 2010
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/...ocs/1.0/ui.html

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

:nathaN
 
  11 November 2010
thanks for your help. much appreciated
 
  11 November 2010
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

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


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