Hi,
I’m trying to setup a UI that contains any number of sliders (it’s dynamically built), that when you slide one slider, the others update to make sure the sum total of all the sliders is equal to 100.
Like how the Humble Bundle sliders work : https://www.humblebundle.com/ (step 2, at bottom)
Right now with my code (below), all sliders normalize to 100 but they all snap to the same value. I want to be able to add or subtract from the current value, but I’m not sure how to determine if the active slider is increasing or decreasing in value.
Here’s my code so far:
build generic MAYA examples floatSliderGrp window
window = cmds.window(title=‘floatSliderGrp Example’)
cmds.columnLayout()
cmds.floatSliderGrp(‘Group1’, label=‘Group 1’, field=True, minValue=-0, maxValue=100, value=25, dc=‘normalize_slider_weights(“Group1”)’ )
cmds.floatSliderGrp(‘Group2’, label=‘Group 2’, field=True, minValue=-0, maxValue=100, value=25, dc=‘normalize_slider_weights(“Group2”)’ )
cmds.floatSliderGrp(‘Group3’, label=‘Group 3’, field=True, minValue=-0, maxValue=100, value=25, dc=‘normalize_slider_weights(“Group3”)’ )
cmds.floatSliderGrp(‘Group4’, label=‘Group 4’, field=True, minValue=-0, maxValue=100, value=25, dc=‘normalize_slider_weights(“Group4”)’ )
cmds.showWindow( window )
def normalize_slider_weights(self) :
print(self)
groups = [‘Group1’,‘Group2’,‘Group3’,‘Group4’]
values = {}
self_value = 0
for group in groups :
if group == self :
self_value = cmds.floatSliderGrp(group, q=1, v=1)
final_value = (100 - self_value) / 4
print final_value
for group in groups :
if group == self :
continue
cmds.floatSliderGrp(group, e=1, v=final_value)
Thanks for taking a look!
Adrian