Oddity with AddUndo()

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/10/2009 at 07:56, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   10-11.5 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
In my plugin I'm altering bone deformers and as part of that process, I need to send a message to a bone to fix it and its children. This is intended to be exactly the same as hitting the 'Fix with children' button in the attribute manager for the bone.

This is the code snippet as it stands:

> dc.id = DescID(BONEOBJECT_FIXCHILDS); \> doc->AddUndo(UNDO_CHANGE, boneObj); \> boneObj->Message(MSG_DESCRIPTION_COMMAND, &dc;); \>

The problem is that undoing this action requires two Ctrl-Z keystrokes (or clicking the undo icon on the toolbar). I'd like to have it only needing one, as in the AM. Is it possible to do that?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/10/2009 at 14:35, xxxxxxxx wrote:

Have you tried it without doc->AddUndo()? It is possible that an undo is being created automatically.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/10/2009 at 15:08, xxxxxxxx wrote:

Yes, I tried that and it doesn't make any difference, I still have to do two Ctrl-Zs to undo the complete operation. Which makes me think that the AddUndo() is having no effect - i.e., that it isn't adding an undo for this operation.

All the other operations in that function - which are mostly SetRot() and SetPos() calls - have an AddUndo() before they are called and all work fine, but not that particular call.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 24/10/2009 at 17:33, xxxxxxxx wrote:

Have you called doc->StartUndo()/EndUndo() around these calls?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/10/2009 at 05:06, xxxxxxxx wrote:

Yes, indeed. I should have said that this routine is part of a much larger series of function calls which all have AddUndo() in them where needed - and all of which work fine - and the whole thing begins and ends with StartUndo()/EndUndo().

The only part of the entire process which doesn't seem to undo correctly is that one code snippet. Everything else is fine.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/10/2009 at 13:18, xxxxxxxx wrote:

Howdy,

It could be that somewhere you have a StartUndo()/EndUndo() nested within another StartUndo()/EndUndo().

I had that problem once, and when I removed the inner set of start and end undos, it solved the problem. ;o)

Adios,
Cactus Dan

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/10/2009 at 17:57, xxxxxxxx wrote:

That is definitely a possibility. Both Dan and I have been through this nesting issue in the past. :)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 25/10/2009 at 19:05, xxxxxxxx wrote:

A long shot maybe (I'm in COFFEE only).
Could it be related to the issue in COFFEE scripting that a
CommandCall() does not get included in an Undo
but a SendModellingCommand() does?

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 02:19, xxxxxxxx wrote:

Quote: _It could be that somewhere you have a StartUndo()/EndUndo() nested within another StartUndo()/EndUndo().
>
> * * *
_


Thanks Dan, that's a great idea. I've now checked it and there's only one StartUndo()/EndUndo() pair in the code. I also looked to see if a recursive routine, of which I have several here, might have called them more than once, but no go. It's really odd.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 02:23, xxxxxxxx wrote:

Quote: A long shot maybe (I'm in COFFEE only).
>
> * * *
>
> Could it be related to the issue in COFFEE scripting that a
> CommandCall() does not get included in an Undo
> but a SendModellingCommand() does?
>
> * * *

Thanks Lennart. I wasn't aware of that issue, so that's useful to know.

I guess it could be related, but I'm not sure what the relationship between CommandCall(), SendModellingCommand(), and sending a description command message to an object is. Do they all end up doing essentially the same thing?

It would be nice to be able to try another method of accessing this command. Anyone know if that's possible?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 04:36, xxxxxxxx wrote:

I can't confirm this. Something like this works perfectly fine:

> \> DescriptionCommand dc; \> dc.id = DescID(DescLevel(BONEOBJECT_FIXCHILDS, DTYPE_BUTTON, op->GetType())); \> \> doc->StartUndo(); \> doc->AddUndo(UNDO_CHANGE, op); \> \> op->Message(MSG_DESCRIPTION_COMMAND, (void\* )&dc;); \> \> doc->EndUndo(); \> \> op->Message(MSG_UPDATE); \> \> EventAdd(); \>

Maybe it's really an issue of nested undos.

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 05:09, xxxxxxxx wrote:

Howdy,

The problem I had with nested StartUndo()/EndUndo() was because I was sending my tag a message from a command to click a button in the AM, but there was a StartUndo()/EndUndo() in the tag's message routine that handled the button click.

It could be that there is a StartUndo()/EndUndo() in the bone's routine to handle that button click.

Adios,
Cactus Dan

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 05:20, xxxxxxxx wrote:

Thanks Matthias. Good to know that AddUndo() does work the way I'm using it. There's clearly a bug in my code somewhere - I'll keep searching!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 06:28, xxxxxxxx wrote:

Thanks Dan. You're probably right, because everything my code does up until the simulated AM button click is reversed in one undo, everything after it (including the 'click' itself) is reversed by the second undo.

The thing is, the button click has to come in the middle of code which is enclosed by a StartUndo()/EndUndo() pair. So I'm not sure there's a way round this unless there's a method to fix bones without simulating the button click.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 07:46, xxxxxxxx wrote:

I was going to say before that calling a command like this (simulating a button press) will probably create an automatic undo. The same thing happens when I convert my plugin bone hierarchy into a C4D bone hierarchy - requires two undos to go back. There is nothing that I know of to avoid this.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 26/10/2009 at 09:31, xxxxxxxx wrote:

Fair enough. If there's nothing I can do about it, I can live with it! It's when you think that there must be some solution that it drives you mad...