gS7 Posted January 30, 2013 Posted January 30, 2013 Guys Here i am Posting a Routine to erase Object with undo option i got problem here after erasing any object if i press undo .. everything is going back i apologize for my poor English (defun c:Test() (setq cnt 0) (setq x t) (while x (initget "Undo") (setq sel (entsel "\nPick Object to Erase [undo]:")) (cond ( ( = "Undo" sel) (if (> cnt 0) (progn (command "_.u") (setq cnt(1- cnt)) ) (princ "\nUndo Done.") ) ) ( ( = (Type (car sel)) 'ename) (command "_.ERASE" (car sel) "") ) ( (not sel) (setq x nil) ) ) (setq cnt(1+ cnt)) ) ) Quote
Dadgad Posted January 30, 2013 Posted January 30, 2013 I do not write lisp, but it seems likely that you may need to set the UNDOCTL system variable to enforce the behavior you are after. If you do so, don't forget to return it to the previous value before completing the lisp. Quote
MSasu Posted January 30, 2013 Posted January 30, 2013 Dadgad is right, the said variable may have influence on the behavior of your routine, but unfortunately you cannot affect it directly since is Read-Only. Instead, try to create an undo group for each erase operation. (( = (Type (car sel)) 'ename) (command [color=magenta]"_UNDO" "_G" [/color] "_.ERASE" (car sel) "" [color=magenta]"_UNDO" "_E"[/color]) ) Quote
gS7 Posted January 30, 2013 Author Posted January 30, 2013 Yes now working fine Thank u Dadgad & Mircea @ i Corrected codes with your reference thank u again Quote
gS7 Posted January 30, 2013 Author Posted January 30, 2013 (defun c:Test() (setq cnt 0) (setq x t) (while x (initget "Undo") (setq sel (entsel "\nPick Object to Erase [undo]:")) (cond ( ( = "Undo" sel) (if (> cnt 0) (progn (command "_.u") (setq cnt(1- cnt)) ) (princ "\nUndo Done.") ) ) ( ( = (Type (car sel)) 'ename) [color="blue"](command "_UNDO" "_G" "_.ERASE" (car sel) "" "_UNDO" "_E")[/color] [color="blue"] (setq cnt(1+ cnt))[/color] ) ( (not sel) (setq x nil) ) ) ) ) Quote
Lee Mac Posted January 30, 2013 Posted January 30, 2013 Note that entdel can both erase and unerase an entity (since the function simply toggles the erase flag for an entity; entities whose erase flag is set are only lost when the drawing is closed). Consider the following example: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] ext lst sel ) ([color=BLUE]while[/color] ([color=BLUE]null[/color] ext) ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]if[/color] lst ([color=BLUE]initget[/color] [color=MAROON]"Undo"[/color])) ([color=BLUE]setq[/color] sel ([color=BLUE]entsel[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nPick Object to Erase"[/color] ([color=BLUE]if[/color] lst [color=MAROON]" [undo]: "[/color] [color=MAROON]": "[/color])))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]=[/color] [color=MAROON]"Undo"[/color] sel) ([color=BLUE]if[/color] lst ([color=BLUE]progn[/color] ([color=BLUE]entdel[/color] ([color=BLUE]car[/color] lst)) ([color=BLUE]setq[/color] lst ([color=BLUE]cdr[/color] lst)) ) ) ) ( ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ([color=BLUE]car[/color] sel))) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]car[/color] sel) lst)) ([color=BLUE]entdel[/color] ([color=BLUE]car[/color] sel)) ) ( ([color=BLUE]setq[/color] ext [color=BLUE]t[/color]) ) ) ) ([color=BLUE]princ[/color]) ) Quote
Dadgad Posted January 30, 2013 Posted January 30, 2013 Note that entdel can both erase and unerase an entity (since the function simply toggles the erase flag for an entity; entities whose erase flag is set are only lost when the drawing is closed). Consider the following example: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] ext lst sel ) ([color=BLUE]while[/color] ([color=BLUE]null[/color] ext) ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]if[/color] lst ([color=BLUE]initget[/color] [color=MAROON]"Undo"[/color])) ([color=BLUE]setq[/color] sel ([color=BLUE]entsel[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nPick Object to Erase"[/color] ([color=BLUE]if[/color] lst [color=MAROON]" [undo]: "[/color] [color=MAROON]": "[/color])))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]=[/color] [color=MAROON]"Undo"[/color] sel) ([color=BLUE]if[/color] lst ([color=BLUE]progn[/color] ([color=BLUE]entdel[/color] ([color=BLUE]car[/color] lst)) ([color=BLUE]setq[/color] lst ([color=BLUE]cdr[/color] lst)) ) ) ) ( ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ([color=BLUE]car[/color] sel))) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]car[/color] sel) lst)) ([color=BLUE]entdel[/color] ([color=BLUE]car[/color] sel)) ) ( ([color=BLUE]setq[/color] ext [color=BLUE]t[/color]) ) ) ) ([color=BLUE]princ[/color]) ) So that is all that the OOPS command does, for the last entity, is turn the lights back on? Quote
gS7 Posted January 30, 2013 Author Posted January 30, 2013 Thank You so much lee Every time We are Learning Something new from you Quote
Lee Mac Posted January 30, 2013 Posted January 30, 2013 So that is all that the OOPS command does, for the last entity, is turn the lights back on? Precisely Thank You so much lee Every time We are Learning Something new from you You're welcome Ganesh Quote
gS7 Posted March 26, 2013 Author Posted March 26, 2013 Here i got another Problem How to undo with multiple Objects Example (defun c:test ( / ext lst sel ) (while (null ext) (setvar 'errno 0) (if lst (initget "Undo")) (setq sel (entsel (strcat "\nPick Object to Erase" (if lst " [undo]: " ": ")))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= "Undo" sel) (if lst (progn (entdel (car lst)) (setq lst (cdr lst)) ) ) ) ( (= 'ename (type (car sel))) (setq lst (cons (car sel) lst)) [color="red"](setq sss (ssget "x" (list (cons 8 (cdr (assoc 8 (entget (car sel))))))))[/color] [color="red"](command "erase" sss "")[/color] ) ( (setq ext t) ) ) ) (princ) ) Quote
MSasu Posted March 26, 2013 Posted March 26, 2013 I suppose this is what you were trying to achive (sorry, I didn't marked the changes): (defun c:test ( / ext sel sss ) (while (null ext) (setvar 'errno 0) (if sss (initget "Undo")) (setq sel (entsel (strcat "\nPick Object to Erase" (if sss " [undo]: " ": ")))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= "Undo" sel) (if (> (sslength sss) 0) (repeat (sslength sss) (entdel (ssname sss 0)) (ssdel (ssname sss 0) sss) ) ) ) ( (= 'ename (type (car sel))) (setq sss (ssget "x" (list (cons 8 (cdr (assoc 8 (entget (car sel)))))))) (command "erase" sss "") ) ( (setq ext t) ) ) ) (princ) ) Quote
gS7 Posted March 26, 2013 Author Posted March 26, 2013 Yes exactly You are Right Mircea code working now but here i had another problem ,That is it will undoing with only one selection set, if i select more then one not working .. Quote
MSasu Posted March 26, 2013 Posted March 26, 2013 This is because the sss variable got reset at each selection action - try to store the previous contents into a list and parse it to undo. Quote
gS7 Posted March 26, 2013 Author Posted March 26, 2013 This is because the sss variable got reset at each selection action - try to store the previous contents into a list and parse it to undo. Please I need help again to update codes from you Quote
MSasu Posted March 26, 2013 Posted March 26, 2013 This is what I have suggested: (defun c:test ( / ext sel sss listOfSelSets ) (while (null ext) (setvar 'errno 0) (if sss (initget "Undo")) (setq sel (entsel (strcat "\nPick Object to Erase" (if sss " [undo]: " ": ")))) (cond ((= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ((= "Undo" sel) (if listOfSelSets (progn (setq sss (car listOfSelSets) listOfSelSets (cdr listOfSelSets)) (repeat (sslength sss) (entdel (ssname sss 0)) (ssdel (ssname sss 0) sss) ) ) (prompt "\nNothing to undo...") ) ) ((= 'ename (type (car sel))) (setq sss (ssget "x" (list (cons 8 (cdr (assoc 8 (entget (car sel)))))))) (command "erase" sss "") (setq listOfSelSets (cons sss listOfSelSets)) ) ((setq ext t)) ) ) (princ) ) Quote
gS7 Posted March 26, 2013 Author Posted March 26, 2013 Wow!! Thank you so much Mircea , Now I Understood Thank u again for your Help Regards Ganesh Shetty 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.