problem with undo in pymel window

22 views
Skip to first unread message

sberger

unread,
Apr 3, 2009, 9:57:46 AM4/3/09
to python_inside_maya
Hi, I am using pymel to build this window. in my Apply button I am
using lambda in the command flag:

applyButton = pm.button( height=buttonHeight, label='Apply',
command=lambda *args: _windowApply(window, False) )

In the aply function, I grab values from the window and use these
values to call another command ... my randomize command:
# get translate values
if trEnable:
trRelative = pm.radioButtonGrp('TranslateRelAbsRadio', q=True,
select=True)
trX = pm.floatSliderGrp('TranslateXslider', q=True, value=True)
trY = pm.floatSliderGrp('TranslateYslider', q=True, value=True)
trZ = pm.floatSliderGrp('TranslateZslider', q=True, value=True)
# call the randomize command
avRandom.randomTranslate((trX,trY,trZ), trRelative)

this randomize command loops the selection and apply a random value in
translate, rotate or scale.

here is the catch:
When running the randomize command on a few object, then do undo, all
the translate on all objects are undo-ed in one go.
When I run the _windowsApply() by itself (for debuging purpose), the
undo works... it undos all the translate of all the objects in one go.

BUT

When I run it by pressing my apply button (i.e the _windowsApply() is
called through the lambda function ... then the undo undo each object
one after the other instead of all of them in one go....

Anyone have any idea why that is?

Sylvain Berger

unread,
Apr 3, 2009, 10:58:31 AM4/3/09
to python_inside_maya
Yup it really is because of the lambda function... I change the apply button command to this:
applyButton = pm.button( height=buttonHeight, label='Apply', command='avRandomizer._windowApply("%s", %d)' %(window, False) )

baking the command into a dumb string, and the undo work as expected.

I am suspecting that the lambda function is going through the code, building some sort of huge command list. When I call the lambda function Maya is not recording one command but many commands, thus giving me this undo problem.

I would still really like to be able to use lambda function in my window command, because sometimes sending a command as a string is not possible... like if I want to send a list to my function, building a string might prove problematic.

--
They say, "Evil prevails when good men fail to act." What they ought to say is, "Evil prevails."
Nicolas Cage as Yuri Orlov in Lord of War.

Ofer Koren

unread,
Apr 3, 2009, 10:46:22 PM4/3/09
to python_in...@googlegroups.com
Instead of the lambda use pymel's Callback object - it handles the undo without having to 'stringify' your commands:


def randomize():
   ....

...

pm.button(l="My Button", c=pm.Callback(randomize))    # pass in a pointer to the function






Reply all
Reply to author
Forward
0 new messages