LauKwokFai Posted August 27, 2012 Share 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 Link to comment Share on other sites More sharing options...
Dadgad Posted August 27, 2012 Share 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 Link to comment Share on other sites More sharing options...
LauKwokFai Posted August 27, 2012 Author Share 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 Link to comment Share on other sites More sharing options...
Tharwat Posted August 27, 2012 Share Posted August 27, 2012 (setq os (getvar 'osmode)) (setvar 'osmode 0) ;;; you codes here ... (setvar 'osmode os) Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted August 27, 2012 Author Share 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 Link to comment Share on other sites More sharing options...
Tharwat Posted August 27, 2012 Share 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 Link to comment Share on other sites More sharing options...
Lee Mac Posted August 27, 2012 Share 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 Link to comment Share on other sites More sharing options...
LauKwokFai Posted August 27, 2012 Author Share 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 Link to comment Share on other sites More sharing options...
neophoible Posted August 30, 2012 Share 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 Link to comment Share on other sites More sharing options...
ketxu Posted August 31, 2012 Share 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 Link to comment Share on other sites More sharing options...
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.