Jump to content

How do I protect the user's system variables better?


dallion

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...