Small Fish Posted June 14, 2009 Posted June 14, 2009 My code draws some lines etc. halfway through it gets to an "if" statement. If the answer is True then it carries on and completes. However if the answer is Nil then it exits and restores system variables. However I would also like to undo and restore the drawing to how it was originally. How can I do this by using "UNDO" or otherwise. If I use UNDO how many times do I need to UNDO. Thanks for your help Quote
Lee Mac Posted June 14, 2009 Posted June 14, 2009 If you mean so that the user can UNDO what has been created in one hit, then you could use: (command "_.undo" "_Begin") and (command "_.undo" "_End") or (vla-StartUndoMark) and (vla-EndUndoMark) Or, if you want the program to do it, I would keep a list of what you have created and use either entdel or vla-delete. Quote
Small Fish Posted June 14, 2009 Author Posted June 14, 2009 I want to do it programatically - but how do I bring back the old object. Perhaps it would be better to make a block? Surely there is a better way? My attempt: (command "_.COPY" enaPline enaPlineTop "" '(0 0 0) '(0 0 0) ;copy 2 objects "_.LAYER" "_MAKE" "Mylayer" "" ) (setq e1 (entlast)) do some stuff....... (setq e2 (entlast));save new object do a if statement - find answer requires to go back to original object (if blah blah (progn (entdel e2);delete new entity (????? e1 );bring back existing e1 object ? ) ) Quote
Lee Mac Posted June 14, 2009 Posted June 14, 2009 I'm not sure of the rest of the code, so I can't really help you very easily with that snippet Quote
David Bethel Posted June 14, 2009 Posted June 14, 2009 If you used (entdel e1) to erase it, you can (entdel e1) to recover it. At least I think that is your question. -David Quote
Small Fish Posted June 14, 2009 Author Posted June 14, 2009 David thanks - Can you really use entdel to bring back an object? Below is some test code. I have used entdel to try and reinstate the object. But it doesn't work. Perhaps I need to make a block, insert it, then explode it, but this seems kind of clumsy. (defun c:Original (/ enaPline LowLeft e1 e2 ObjName) (vl-load-com) (setq enaPline (car (entsel "\nSelect closed pline rectangle: "))) (setq e1 (entlast)) (setq ObjName (vlax-ename->vla-object enaPline)) (vla-GetBoundingBox ObjName 'LowLeft 'UpRight) (setq LowLeft (vlax-safearray->list LowLeft)) (command "ROTATE" enaPline "" LowLeft 35 ) (setq e2 (entlast)) (command "delay" 3000);slow down to see whats happening (if (not(equal 1000 1200 ));test example numbers (entdel e2);delete modified object (entdel e1);reinstate original object - this is my problem line ) );defun Quote
Lee Mac Posted June 15, 2009 Posted June 15, 2009 If its just a simple Rotation, why not just rotate the object back to where it was? (defun c:Original (/ pEnt pObj Minp Maxp) (vl-load-com) (if (setq pEnt (car (entsel "\nSelect Closed Pline Rectangle: "))) (progn (setq pObj (vlax-ename->vla-object pEnt)) (vla-GetBoundingBox pObj 'Minp 'Maxp) (vla-Rotate pObj Minp (* pi (/ 35. 180.))) (initget "Yes No") (if (= "Yes" (getkword "\nReinstate Original? <No>: ")) (vla-Rotate pObj Minp (* pi (/ -35. 180.))))) (princ "\n<< Nothing Selected >>")) (princ)) A few things: Use a conditional statement (like IF) to allow for the case in which a user doesn't select something. Entlast is used to pick up the last entity created, an entity will still be called by the same entity name if rotated. Why the delays? And comparison of random numbers? Quote
Small Fish Posted June 15, 2009 Author Posted June 15, 2009 thanks Lee Mac - sorry if I am not clear. The code I wrote was just an example - it just happened to be 'rotate' that I used. My original code is just to large to post so I just made something that I thought would explain my problem, hence delays and random comparsion of numbers - I just thought it would show what is happening. My problem is how do I reinstate the original object after modifying it. Edit..... never mind I have worked out one way to do it. First make a points list of all the vertices. Then at the end re draw it using: (command "_PLINE") (mapcar 'command PntLst) (command "c") so I now have: (defun c:Original (/ enaPline LowLeft e1 e2 ObjName PntLst) (vl-load-com) (setq enaPline (car (entsel "\nSelect closed pline rectangle : "))) ;make a list of all vertices (setq eprPline(entget enapline)) (foreach lstTemp eprPline (if (= (car lstTemp) 10) (setq PntLst (append PntLst (list (cdr lstTemp)))) );if );foreach (setq ObjName (vlax-ename->vla-object enaPline)) (vla-GetBoundingBox ObjName 'LowLeft 'UpRight) (setq LowLeft (vlax-safearray->list LowLeft)) (command "ROTATE" enaPline "" LowLeft 35 ) (setq e2 (entlast)) (command "delay" 3000);slow down to see whats happening (if (not(equal 1000 1200 ));test example numbers (progn (entdel e2);delete modified object (command "_PLINE") (mapcar 'command PntLst) (command "c");reinstate object ) ) );defun Quote
Lee Mac Posted June 15, 2009 Posted June 15, 2009 Ok, but take note of the pointers I have provided, you will have a much more stable routine. Also, here is another way to retrieve the vertices of the LWPolyline: (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= (car x) 10))) (entget enapline))) Quote
David Bethel Posted June 15, 2009 Posted June 15, 2009 Yes, you can restore an entity using (entdel) (entdel ename) The entity specified by ename is deleted if it is currently in the drawing. The entdel function restores the entity to the drawing if it has been deleted previously in this editing session. I see that is not what your are trying to accomplish though. -David Quote
Small Fish Posted June 15, 2009 Author Posted June 15, 2009 Thanks David and Lee for the interesting other possibilities I could use in the future cheers Small Fish Quote
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.