dallion Posted December 13, 2012 Share Posted December 13, 2012 My program uses a simple error catch as the only exit point. The problem is the user can undo the setvar calls that reset the system variables and leave the variables in a undesirable state. "Undo" "C" "NONE" will make all previous actions undoable. How do we make it impossible to undo the setvar's while not blowing away the entire undo history? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 13, 2012 Share Posted December 13, 2012 I use this structure: (defun c:mycommand ( / *error* ) (defun *error* ( m ) [color=green]< Reset System Variables >[/color] (LM:endundo (LM:acdoc)) < ... > ) (LM:startundo (LM:acdoc)) [color=green]< Set System Variables >[/color] < ... > [color=green]< Reset System Variables >[/color] (LM:endundo (LM:acdoc)) ) With the following library functions: [color=GREEN];; Start Undo - Lee Mac[/color] [color=GREEN];; Opens an Undo Group.[/color] ([color=BLUE]defun[/color] LM:startundo ( doc ) (LM:endundo doc) ([color=BLUE]vla-startundomark[/color] doc) ) [color=GREEN];; End Undo - Lee Mac[/color] [color=GREEN];; Closes an Undo Group.[/color] ([color=BLUE]defun[/color] LM:endundo ( doc ) ([color=BLUE]while[/color] ([color=BLUE]=[/color] 8 ([color=BLUE]logand[/color] 8 ([color=BLUE]getvar[/color] 'undoctl))) ([color=BLUE]vla-endundomark[/color] doc) ) ) [color=GREEN];; Active Document - Lee Mac[/color] [color=GREEN];; Returns the VLA Active Document Object[/color] ([color=BLUE]defun[/color] LM:acdoc [color=BLUE]nil[/color] ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'LM:acdoc '[color=BLUE]nil[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))) (LM:acdoc) ) When considering the order of operations & Undo Group markers within the program & error handler, be aware that when an Undo call is issued, AutoCAD will undo all operations following the end of an Undo Group before Undo'ing the Group. Quote Link to comment Share on other sites More sharing options...
dallion Posted December 13, 2012 Author Share Posted December 13, 2012 Thanks Lee Mac. I didn't mention I needed it to step back through a loop, but your post gave me the pattern to make it work. Now, I just need to learn the fancy VLA stuff so I quiet it down....(command "_.undo...) is noisy! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 14, 2012 Share Posted December 14, 2012 You're welcome! (command "_.undo...) is noisy! Temporarily disable CMDECHO Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.