Jump to content

How to reset OSNAP while a Lisp been teminated


LauKwokFai

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
 )

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...