Undo lisp somehow not working

Undo lisp somehow not working

r.kuijs
Explorer Explorer
1,035 Views
3 Replies
Message 1 of 4

Undo lisp somehow not working

r.kuijs
Explorer
Explorer

Hey everybody!

 

I am new to Lisp so I might write or show some things that look wrong or convoluted.

 

I have written a Lisp that deletes everything i a drawing except for certain things. It deletes the layouts and  detaches the xrefs, to then purge everything. Then it Dxfouts that which has been left. 

 

Now I want to simply undo. I want to undo basically everything i just listed, with exception -of course- of the Dxfout.

 

I tried using this:

(vl-load-com)
(vla-StartUndoMark (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object))))
...
(vla-EndUndoMark *DOC*)

 

I tried using the (command "_.undo" "be")  and then (command "_undo" "end"); I tried using the _undo group and using the _undo mark.

It doesn't work.

 

Here is the code:

 

(defun c:purge ()

  	
	(command "Layer" "s" 0 "")
  	(command "model")
  	(command "save" "")
  	(command "-xref" "D" "*")
  
(vl-load-com)
  (vlax-for layout (vla-get-layouts
      (vla-get-ActiveDocument (vlax-get-acad-object))
   )

    (if	(/= (vla-get-name layout) "Model")
      (vla-delete layout)
    )
	

 )

(setq sel1 (ssget "x" (list 	(cons 8 "~lotsoflayernames"))))
					
					
  	(command "_.erase" sel1 "")
	(command "_.purge" "_all" "*" "_no")
  	
	(command "_.dxfout" "" "V" "R12" "")
  	
  )

 

Now where do I place any of these undo-thingies? Am I missing something obvious?

 

Help and input is greatly appreciated.

0 Likes
Accepted solutions (1)
1,036 Views
3 Replies
Replies (3)
Message 2 of 4

hak_vz
Advisor
Advisor

Here is template I use regularly in my code.

(defun c:somefunction( / adoc *error*)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(princ)
	)

	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	;....


	(vla-endundomark adoc)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

@r.kuijs wrote:

....

I tried using this:

(vl-load-com)
(vla-StartUndoMark (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object))))
...
(vla-EndUndoMark *DOC*)

 

I tried using the (command "_.undo" "be")  and then (command "_undo" "end"); I tried using the _undo group and using the _undo mark.

It doesn't work.

....


You should be able, after that EndUndoMark, to just do:

  (command "_.u")

Note that U is not an alias for UNDO, but a command of its own, equivalent to:

  (command "_.undo" "")

which accepts the default to Undo 1 operation, which would be what you wrapped in the StartUndoMark and EndUndoMark functions.

 

You don't show exactly how you tried using Undo Begin/End or Mark.  You should be able to skip the VLA business and its version of Undo Begin/End, and use the Mark and Back options:

 

(defun c:purge ()
  (command "_.undo" "_mark")
  (command "Layer" "s" 0 "")
  .... etc ....
  (command "_.dxfout" "" "V" "R12" "")
  (command "_.undo" "_back")
)

 

Even though that looks like it "undoes" the DXFOUT, it doesn't really, because it can't reach outside the drawing to delete the file that was created.

Kent Cooper, AIA
Message 4 of 4

r.kuijs
Explorer
Explorer

> You should be able, after that EndUndoMark, to just do:

  (command "_.u")

 

Thank you very much! This is the basic thing that I was overlooking. I Thought that putting the begin and end mark would suffice; In other words I thought that the endundomark would execute the undoing. (If that makes any sense)

 

All my Lisp coding has only been possible because of the kind people that are willing to answer questions on Forums like these. So thank you @Kent1Cooper@hak_vz and the many other kind people, that contribute their knowledge on these Forums.

0 Likes