Undo Script

On 21/09/2015 at 20:23, xxxxxxxx wrote:

So, first post, noob question. :blush:  
  
I have these two really simple scripts that save me some clicks every now and then.  
All I want to do is undo them in one go but for the life of me I can't figure out how.  
  
  
1: To make a single mesh out of anything (e.g. cloner object)   
//-------------------------------------------------------------------------------------  
def main() :  
    bc = c4d.GetWorldContainerInstance()    # Get the Prefs  
    oldInsertAt = bc[c4d.WPREF_INSERTAT]    # Get the current Insert setting  
    bc[c4d.WPREF_INSERTAT] = 3         # Set to Parent  
    c4d.CallCommand(100004772) # Group Objects  
    c4d.CallCommand(1011010) # Connect  
    c4d.CallCommand(12236) # Make Editable  
    bc[c4d.WPREF_INSERTAT] = oldInsertAt # Reset the pref to original value  
if \__name\_\_=='\__main\_\_':  
    main()  
  
//-------------------------------------------------------------------------------------  
  
  
  
2: Delete polygons + optimize when in polygon/point mode  
   or optimize when in edge mode  
//-------------------------------------------------------------------------------------  
mode = doc.GetMode()  
if mode==c4d.Medges: #in edge mode  
 c4d.CallCommand(440000043) # Dissolve  
elif mode!=c4d.Medges: #Not in edge mode  
 c4d.CallCommand(12109) # Delete  
 c4d.CallCommand(14039) # Optimize...  
  
//-------------------------------------------------------------------------------------  
  
Any thoughts? please!![Lamp](http://www.plugincafe.com/forum/smileys/smiley38.gif)  

On 22/09/2015 at 04:21, xxxxxxxx wrote:

Hi,

welcome to the Plugin Café forums 🙂

Unfortunately it's not going to work.
Normally you'd use StartUndo(), AddUndo() and EndUndo() to create undo steps. But in your case you are using CallCommand(), which (as the name already says) calls Cinema4D's built-in commands. These commands usually handle undo on their own and thus create their individual separate undo steps. Nothing much you can do about it.
Some of the commands you are using are quite easy to implement yourself. So you could at least reduce the number of undo steps, by implementing these yourself and thus having full control over the undo steps using above commands.

On 22/09/2015 at 05:54, xxxxxxxx wrote:

So, that's why everything I tried didn't work.

Huge thanks Andreas for taking the time 🤝