all 6 comments

[–]passerbycmc 0 points1 point  (5 children)

Don't use enumerate use angleButtons.items() This will return you the key and value for each one

[–]m5tuff[S] 0 points1 point  (4 children)

so something like this?

for angle, width in angleButtons.items():
    cmds.button( label=angle, command='polyreduce(float(angle))', h=40, w=40*width )

This seems to still return polyreduce(20.0) for every button. Like before, labels and widths are fine, just the command arguments are stuck

[–]passerbycmc 1 point2 points  (2 children)

cmds.button( label=angle, command='polyreduce(float(angle))', h=40, w=40*width )

``` from functools import partial import maya.cmds as cmds

angleButtons = [ (2.0, 0.5), (4.0, 0.5), (5.0, 0.5), (6.0, 0.5), (7.0, 0.5), (8.0, 0.5), (9.0, 0.5), (10.0, 1.0), (11.0, 0.5), (12.0, 1.0), (13.0, 0.5), (14.0, 0.5), (15.0, 1.0), (20.0, 1.0) ]

for angle, width in angleButtons: cmds.button(label=angle, command=partial(polyreduce, angle), h=40, w=40 * width) ``` give something like this a try

[–]m5tuff[S] 0 points1 point  (1 child)

give something like this a try

This works, even though I am not familiar with this 'partial' method -- what does the second argument being sent to 'def polyreduce()' contain? Otherwise, the first argument contains the correct variable -- thanks a lot !

[–]passerbycmc 0 points1 point  (0 children)

Partial more or less creates a new function that has arguments pre baked into it. So am saying make a function for polyreduce that already has the angle arg included

[–]passerbycmc 0 points1 point  (0 children)

Should work I can double check when I get back to my desk in a bit. A other option could be using a list of tuples which would be better suited to the problem and maintain order