floatSliderGrp HOW do I add a listener to the slider so as it moves you get updates?

1,689 views
Skip to first unread message

Geordie Martinez

unread,
Apr 12, 2012, 2:31:43 PM4/12/12
to python_inside_maya
I have a floatSliderGrp that I need to spit back interactive updates
to the slider.
is there a callback or command that can watch the slider handle?

Jesse Capper

unread,
Apr 12, 2012, 2:43:57 PM4/12/12
to python_inside_maya
changeCommand is executed when the value is changed, and only once
after a drag of the slider.
dragCommand is executed repeatedly during the drag of the slider.

-----------
Code sample:

def slider_drag_callback(*args):
print 'Slider Dragged'

def value_change_callback(*args):
print 'Value Changed'

window = cmds.window()
cmds.columnLayout()
cmds.floatSliderGrp(label='Drag Callback', field=True, value=0,
dc=slider_drag_callback)
cmds.floatSliderGrp(label='Change Callback', field=True, value=0,
cc=value_change_callback)
cmds.showWindow(window)

On Apr 12, 11:31 am, Geordie Martinez <geordiemarti...@gmail.com>
wrote:

Geordie Martinez

unread,
Apr 12, 2012, 3:45:44 PM4/12/12
to python_inside_maya
AWESOME. thanks.

Daz

unread,
May 25, 2013, 8:12:41 AM5/25/13
to python_in...@googlegroups.com
Heya

I'm working on something similar but I get strange error. Could any have a look at my piece of code too and let me know why I don't get call back of the value I put in to my slider?

import maya.cmds as cmds

def AlphaValue(SliderName,AlphaName):
if cmds.ls(sl=1,mat=1):
sel=cmds.ls(sl=1,mat=1)
for alpha in sel:
value=cmds.floatSliderGrp(SliderName,query= True,field=True)
print value
cmds.setAttr('%s.%s'%(alpha,AlphaName),value[0])

windowZ=cmds.window(title="Slider Test",w=350,h=250)
cmds.columnLayout(w=150,adj=True)
diffuseAmountSlider=cmds.floatSliderGrp(label="Zoom", field=True,dc='AlphaValue(diffuseAmountSlider,"diffuseColorAmount")',value=1,min=-0.001,max=1,pre=3)
cmds.showWindow(windowZ)

I cant break it no matter what I try :(

Daz

unread,
May 25, 2013, 3:05:36 PM5/25/13
to python_in...@googlegroups.com
Solved. Not sure how it just stared to work after I retype it for 10x...

Justin Israel

unread,
May 25, 2013, 6:16:31 PM5/25/13
to python_in...@googlegroups.com
Just a suggestion, but you may find it a lot easier to work with actual function objects, as opposed to passing a string for the callback, to be evaluated. When you pass a string it is not a closure and anything in there will get evaluated when it is executed. So you could change your callback to this (using one of my favorite python tools: functools.partial):

from functools import partial
callback = partial(AlphaValue, diffuseAmountSlider, "diffuseColorAmount")

the partial() function will take a function and its arguments and wrap them up into a single callable object, which you can then pass around. You could even pass more arguments to that new callable, which will be added onto the final call:

def colors(required, optional1=None, optional2=None):
print required, optional1, optional2

colorFunc = partial(colors, optional2='red')
colorFunc('green')
# green None red
> --
> You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
> To post to this group, send email to python_in...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages