LauKwokFai Posted August 27, 2012 Posted August 27, 2012 I would like to know if it is possible to reset the OSNAP back to the initial setting when a lisp is being terminated. For example, my initial setting for "OSMODE" is 47, for some reason I may need to set the "OSMODE" to 0 to make sure it won't snap to the objects nearby, but if I terminate this lisp now, I will have to set the "OSMODE" again. Can anyone help ? Thanks so much Quote
Dadgad Posted August 27, 2012 Posted August 27, 2012 Sorry I don't know how to tell you to do it, but I do know that a well written list will do exactly what you are asking about. Save your prelisp OSMODE setting, and restore it either after completion, or upon escaping out of it, should that happen. Somebody will certainly clarify how to do it for you. I bet if you went to http://www.lee-mac.com/programs.html, and looked at any one of Lee Mac's great lisps there, you would quickly see how it SHOULD be done, from within the lisp. Quote
LauKwokFai Posted August 27, 2012 Author Posted August 27, 2012 Thanks Dadgad, I actually had been looking at Lee Mac's great lisps for a while, for I am really not very good at this, I haven't found any solution, or even, I am not smart enough to understand. I don't know if it has anything to do with *error*, I am still looking at it. Quote
Tharwat Posted August 27, 2012 Posted August 27, 2012 (setq os (getvar 'osmode)) (setvar 'osmode 0) ;;; you codes here ... (setvar 'osmode os) Quote
LauKwokFai Posted August 27, 2012 Author Posted August 27, 2012 Thanks Tharwat, I have included the code you suggested in my lisp, my problem is the lisp is being terminated before it reached the line (setvar "osmode" os), e.g. press ESC Quote
Tharwat Posted August 27, 2012 Posted August 27, 2012 the error sub-routine would take care of that ... a few things to consider .. (just an example) (defun c:Test (/ *error* p1 p2 os) (defun *error* (x) (if os (setvar 'osmode os)) (if (eq (strcase x) "*CANCEL*") (princ "\n cancelled ....")) (princ) ) (setq os (getvar 'osmode)) (setvar 'osmode 0) (if (and (setq p1 (getpoint "\n Specify first point :")) (setq p2 (getpoint "\n nexi point :" p1)) ) (command "_.line" p1 p2 "") (princ) ) (setvar 'osmode os) (princ) ) Quote
Lee Mac Posted August 27, 2012 Posted August 27, 2012 ...but if I terminate this lisp now, I will have to set the "OSMODE" again. Are you using 'Esc' to terminate the LISP? If so, you will need to use an *error* handler to reset the environment. Quote
LauKwokFai Posted August 27, 2012 Author Posted August 27, 2012 we didn't mean to terminate the LISP by pressing ESC, we are used to press ESC during the drafting process !! this is the reason why we always lost the OSMODE setting. I am looking the *error* example in Lee Mac programming, it seems working if I add a line (setvar "osmode" my_osmode) within the error sub-routine. I am still testing on it. Thank you Quote
neophoible Posted August 30, 2012 Posted August 30, 2012 Another way to make it easy to recover is to turn off running Osnaps rather than turning off all your Osnap settings. In that case, a crash would just mean toggling OSNAPS back on, e.g., with F3. To turn off running Osnaps in AutoLISP, first save the original value, then mask OSMODE with 16384--like this: (setq OriginalOsmode (getvar "OSMODE")) (setvar "OSMODE" (logior 16384 OriginalOsmode)) This can be handy when dealing with programs that are NYRFPT and don't have an error handler, though an error handler is certainly the best way to go. Of course, you should still have a line to reset: (setvar "OSMODE" OriginalOsmode) Quote
ketxu Posted August 31, 2012 Posted August 31, 2012 You can try this http://xaydungit.vn/diendan/showthread.php?3551-Reset-l%E1%BA%A1i-bi%E1%BA%BFn-OSNAP-sau-khi-d%C3%B9ng-lisp&highlight=reset+osnap Just appload it 1 Quote
Jarryd30 Posted April 10 Posted April 10 (edited) can someone add it to this code for me? I was to run the lisp routine and then once I press 'space' or 'esc' i want it to restore to my previous osmode value (4749) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;UPDATED BY MITCH MACKEZIE TO BETTER SUIT SMEC NEEDS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;3RD OCTOBER 2016;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:tbd () (setq sp nil) (setq ep nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;get entity text or adopt whats there (setq oldormode (getvar "OSMODE")) (setvar "OSMODE" 1) (setq ormode (getvar "OSMODE")) (initget "Y N _Yes No") (setq option (getkword "\nDo you want Select Text for Entity Copy? (Yes / No): ")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (IF (= "Yes" option) (progn (setq txtent (entget(car(entsel "\nPlease click on text entity to adopt style:")))) (setq btstyle (cdr(assoc 7 txtent))) (setq dtstyle (cdr(assoc 7 txtent))) (setq blayer (cdr(assoc 8 txtent))) (setq dlayer (cdr(assoc 8 txtent))) (setq hght (cdr(assoc 40 txtent))) (setq txtcolour (cdr(assoc 62 txtent))) (If (> txtcolour 0) (setq txtcolour (itoa txtcolour))) (If (= txtcolour nil) (setq txtcolour "ByLayer")) (setvar "CLAYER" dlayer) (setvar "TEXTSIZE" hght) (setvar "TEXTSTYLE" dtstyle) (setvar "CECOLOR" txtcolour) ) );End If ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (= "No" option) (setq btstyle "STANDARD" dtstyle "STANDARD" blayer (getvar "CLAYER") dlayer (getvar "CLAYER") hght (getvar "TEXTSIZE") ) );End If (setq layertestbearing (substr blayer 1 7)) (setq layerscalebearing (substr blayer 9 100)) (if (= layertestbearing "BEARING") (progn (setq dlayer (strcat "DISTANCE_" layerscalebearing)) ) ) (setq layertestdistance (substr dlayer 1 8)) (setq layerscaledistance (substr dlayer 10 100)) (if (= layertestdistance "DISTANCE") (progn (setq blayer (strcat "BEARING_" layerscaledistance)) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setvar "cmdecho" 0) (setq td hght) (setvar "angbase" (/ pi 2)) (setvar "angdir" 1) (setq round "Y" dround "2" bround "0" distonly "0") (setq sp (osnap (getpoint "\nStart point:- ") "end")) (While (= Nil sp) (setq sp (osnap (getpoint "\nTry Again Sunshine:- ") "end")) );End While (WHILE (= Nil ep) (setq ep (osnap (getpoint "\nEnd point:- ") "end")) (While (= Nil ep) (setq ep (osnap (getpoint "\nTry Again Sunshine:- ") "end")) );End While ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq radang (angle sp ep)) (setq dista (distance sp ep)) (setq dist dista) (setq mp (polar sp radang (/ dista 2.0))) (setq dp (polar mp (- radang (/ pi 2.0)) td)) (setq bp (polar mp (- radang (/ pi 2.0)) (- 0.00 td))) (setq aa radang) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq degang (- 450.0 (* (/ 180.0 pi) aa))) (if (>= degang 360.0)(setq degang (- degang 360.0))) (setq intd (fix degang)) (setq dec (- degang intd)) (setq minu (* dec 60.0)) (setq iminu (fix minu)) (setq dec (- minu iminu)) (setq sec (* dec 60.0)) (setq isec (fix(atof(rtos sec 2 0)))) (setq sec (itoa isec)) (if (< dist 29.995) (progn (if (>= isec 30)(setq iminu (+ 1 iminu))) (if (= iminu 60)(setq iminu 0 intd (+ 1 intd))) (if (= intd 360)(setq intd 0)) (setq minu (itoa iminu)) (if (< iminu 10)(setq minu (strcat "0" minu))) (setq brg (strcat (itoa intd) "%%d" minu "'")) ) ) (if(and(>= dist 29.995)(< dist 199.995)) (progn (if (< isec 5)(setq sec "")) (if (and (> isec 4)(<= isec 14))(setq sec "10")) (if (and (> isec 14)(<= isec 24))(setq sec "20")) (if (and (> isec 24)(<= isec 34))(setq sec "30")) (if (and (> isec 34)(<= isec 44))(setq sec "40")) (if (and (> isec 44)(<= isec 54))(setq sec "50")) (if (>= isec 55)(setq sec "00" iminu (+ 1 iminu))) (if (= iminu 60)(setq iminu 0 intd (+ 1 intd))) (if (= intd 360)(setq intd 0)) (setq minu (itoa iminu)) (if (< iminu 10)(setq minu (strcat "0" minu))) (if (= sec "")(setq brg (strcat (itoa intd) "%%d" minu "'" )) (setq brg (strcat (itoa intd) "%%d" minu "'" sec (chr 34))) ) ) ) (if (>= dist 199.995) (progn (if (< isec 5)(setq sec "")) (if (and (> isec 4)(<= isec 14))(setq sec "10")) (if (and (> isec 14)(<= isec 24))(setq sec "20")) (if (and (> isec 24)(<= isec 34))(setq sec "30")) (if (and (> isec 34)(<= isec 44))(setq sec "40")) (if (and (> isec 44)(<= isec 54))(setq sec "50")) (if (>= isec 55)(setq sec "00" iminu (+ 1 iminu))) (if (= iminu 60)(setq iminu 0 intd (+ 1 intd))) (if (= intd 360)(setq intd 0)) (setq minu (itoa iminu)) (if (< iminu 10)(setq minu (strcat "0" minu))) (if (= sec "")(setq brg (strcat (itoa intd) "%%d" minu "'" )) (setq brg (strcat (itoa intd) "%%d" minu "'" sec (chr 34))) ) ) ) (setq adjbear brg) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq txtang degang) (if (and (>= txtang 179.5)(< txtang 359.5)) (setq txtang (- txtang 180.0))) (setq dista (rtos dista 2 (atoi dround))) (setq dec (- (atof dista) (atoi dista))) (if (and(= dround "2")(> dec 0.004)(=(strlen(rtos dec)) 3))(setq dista (strcat dista "0"))) (if (and(= dround "3")(> dec 0.004)(=(strlen(rtos dec)) 3))(setq dista (strcat dista "00"))) (if (and(= dround "3")(> dec 0.004)(=(strlen(rtos dec)) 4))(setq dista (strcat dista "0"))) (setq distlength (strlen dista)) (setq TESTDISTA (substr dista (- distlength 2) 3)) (if (= ".00" TESTDISTA)(setq dista (substr dista 1 (- distlength 3)))) (IF (< txtang 90) (progn (setq radang (* pi (/ txtang 180.0))) (setq radang (- 1.5708 radang)) ) ) (IF (AND(> txtang 90)(< txtang 180)) (progn (setq correctionangle (- txtang 90)) (setq radang (* pi (/ correctionangle 180.0))) (setq radang (- 6.28319 radang)) ) ) (IF (AND(> txtang 180)(< txtang 270)) (progn (setq correctionangle (- txtang 90)) (setq radang (* pi (/ correctionangle 180.0))) (setq radang (- 6.28319 radang)) ) ) (IF (> txtang 270) (progn (setq radang (* pi (/ txtang 180.0))) (setq radang (- 6.28319 radang)) (setq radang (+ 1.5708 radang)) ) ) (IF (and(> radang 1.5078)(< radang 3.1416)) (setq radang (- 3.1416 radang)) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 8 dlayer) (cons 10 dp) (cons 40 hght) (cons 1 dista) (cons 50 radang) (cons 41 1) (cons 51 0) (cons 7 dtstyle) (cons 71 0) (cons 72 1) (cons 11 dp) (cons 210 '(0.0 0.0 1.0)) (cons 73 2) )) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 8 blayer) (cons 10 bp) (cons 40 hght) (cons 1 brg) (cons 50 radang) (cons 41 1) (cons 51 0) (cons 7 btstyle) (cons 71 0) (cons 72 1) (cons 11 bp) (cons 210 '(0.0 0.0 1.0)) (cons 73 2) )) (setq sp ep) (setq ep nil) ) ) Edited April 10 by SLW210 Added Code Tags! Quote
SLW210 Posted April 10 Posted April 10 In the future please place your code in code tags. (use the <> in the editor toolbar) Quote
Steven P Posted April 10 Posted April 10 Look at adding an error handler t the LISP, Lee Mac posted a link above or AfraLisp has a good example to work through, and Tharwat has even added it his code above,. I've also noticed that you set OSmode near the begining but can't see where you set it back again at the end? Quote
X11start Posted May 14 Posted May 14 I made this lisp that "simulates" pressing the F3 key. The OSMOFF command is executed only once (to store the current osnap), then in the lisp you can set all the values that are needed for the command itself. On exit, OSMON restores the original Osnap. OsmOnOff.lsp 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.