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




See more in
http://pymel.googlecode.com/svn/docs/pymel.core.windows-module.html



- Ofer
www.mrbroken.com


On Fri, Apr 3, 2009 at 7:58 AM, Sylvain Berger <[email protected]>wrote:

> 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.
>
>
>
> On Fri, Apr 3, 2009 at 9:57 AM, sberger <[email protected]> wrote:
>
>>
>> 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?
>>
>>
>>
>
>
> --
> 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.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to