<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Osmode variable Vs osnap command and its position in lisp routine in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9396115#M76937</link>
    <description>&lt;P&gt;Here you have very often used way to handle osmode on simple (hopefully) example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;Save old&lt;/FONT&gt; osmode, &lt;FONT color="#FF00FF"&gt;set new&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;reset to old&lt;/FONT&gt;. You &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ALWAYS&lt;/FONT&gt;&lt;/STRONG&gt; need to establish the *error* function if you change ANY of system variables to make sure that it resets even in case of &lt;STRONG&gt;ESC&lt;/STRONG&gt;aping/&lt;STRONG&gt;error&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun OMultiple (cur / &lt;FONT color="#FF0000"&gt;*error* osm&lt;/FONT&gt; ent pnt dst)
  
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;  (defun *error* (errmsg)&lt;/STRONG&gt;
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
&lt;STRONG&gt;    (if osm (setvar 'OSMODE osm))&lt;/STRONG&gt;
    (if ent (redraw ent 4))
    (princ)
    )&lt;/FONT&gt;
  
  (if (and (setq ent (ssget "_+.:E:S"))
           (setq ent (ssname ent 0))
           &lt;FONT color="#0000FF"&gt;(setq osm (getvar 'OSMODE))&lt;/FONT&gt; 
           &lt;FONT color="#FF00FF"&gt;(setvar 'OSMODE 0)&lt;/FONT&gt;	
           (not (redraw ent 3))
           )
    (while (setq dst (getdist "\nSpecify offset distance: "))
      (or pnt
          (setq pnt (polar (trans (cdr (assoc 10 (entget ent))) 0 1) (* 1.5 pi) 1)
                dst (abs dst)))
      (command "_.OFFSET" "_E" "_N" "_L" (if cur "_C" "_S") dst ent pnt "")
      (redraw ent 4)
      (redraw (setq ent (entlast)) 3)))

&lt;FONT color="#FF0000"&gt;  (if osm (setvar 'OSMODE osm))&lt;/FONT&gt;
  (if ent (redraw ent 4))
  (princ)
  )

(defun c:OM ()  (OMultiple nil) (princ))
(defun c:OWM () (OMultiple T) 	(princ))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2020 11:31:48 GMT</pubDate>
    <dc:creator>ВeekeeCZ</dc:creator>
    <dc:date>2020-03-24T11:31:48Z</dc:date>
    <item>
      <title>Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9393672#M76930</link>
      <description>&lt;P&gt;Hello kind people of the forum,&lt;/P&gt;&lt;P&gt;Have had a number of you here write me some truly amazing routines &amp;amp; in a bid to try &amp;amp; streamline them even further, I am looking to have only specific snap points/modes available at certain parts in the routines.&lt;/P&gt;&lt;P&gt;Firstly, I am unsure if it is as simple as setting the osmode variable to required integer (quadrants snap for example) &amp;amp; then resetting the variable to mystandard osmode number to reinstate all usual snaps at end of routine. Or...&lt;/P&gt;&lt;P&gt;Do I use the osnap command to specify the desired snap points by name somewhere in the routine?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aside from not being sure in the differences of outcome in these two methods, I have had extremely little success using either method. At the end of a failed lisp routine the snaps have indeed changed but the lisp ceases to run as it did before i tried adding these little cherries on top.&lt;/P&gt;&lt;P&gt;Hopefully this has all made sense without me supplying all the lisps I'm trying to tweak &amp;amp; someone would be kind enough to explain where I would use the osmode variable over the osnap command &amp;amp; where these snippets of code should be placed..?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently working on a lisp that inserts a circular named block in the middle of two other circular blocks so would like to restrict my snapping to quadrants as am dealing with sides/tops of circles. Could someone maybe give me a hint on how to include the above mentioned? Please use your own example if preferred... just something uncomplicated so I can work out the key to it all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you everyone. Hope everyone is doing okay.&lt;/P&gt;&lt;P&gt;Brad&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:36:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9393672#M76930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-23T13:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9393719#M76931</link>
      <description>&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-DD9B3216-A533-4D47-95D8-7585F738FD75-htm.html" target="_blank" rel="noopener"&gt;See the help page on osmode. (2016 version)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;(setvar "osmode" #)&amp;nbsp; where # is the sum of whatever modes you want on (bitflag based #).&lt;/P&gt;
&lt;P&gt;To toggle osnap on and off just negate the #.&lt;/P&gt;
&lt;P&gt;(setvar "osmode" (- (getvar "osmode"))) ;;just toggles the mode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are relatively easy concepts and you should be able to look them up using the vlide help features.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:57:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9393719#M76931</guid>
      <dc:creator>dbroad</dc:creator>
      <dc:date>2020-03-23T13:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394766#M76932</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/411413"&gt;@dbroad&lt;/a&gt;&amp;nbsp;is one of the most helpful and brilliant guys here.&lt;/P&gt;
&lt;P&gt;Unless it's in the help, what Doug didn't explain well enough is that each bit is a Boolean value.&lt;/P&gt;
&lt;P&gt;For example, let's say you have your osnaps set to endpoint (1), that's all.&lt;/P&gt;
&lt;P&gt;To add center (16), you would use (logior 1 16) to get 17.&lt;/P&gt;
&lt;P&gt;Spelling it out... (setvar "osmode" (logior 16 (getvar "osmode")))&lt;/P&gt;
&lt;P&gt;To remove endpoint (1), you would use (boole 2 17 1) to get 16.&lt;/P&gt;
&lt;P&gt;Spelling it out... (setvar "osmode" (boole 2 (getvar "osmode") 1))&lt;/P&gt;
&lt;P&gt;Of course you should save the value of osmode to a variable at the beginning of any program that will change it so that you can restore it just before the program finishes, or exits due to a cancel or error.&lt;/P&gt;
&lt;P&gt;These may save you some time and characters:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(defun add_osmode (n)
  (setvar "osmode" (logior (getvar "osmode") n))
)
(defun del_osmode (n)
  (setvar "osmode" (boole 2 (getvar "osmode") n))
)
(defun is_osmode_set (n)
  (= n (logand (getvar "osmode") n))
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Plus, you can combine bits to add or delete more than one at one time.&lt;/P&gt;
&lt;P&gt;For example (logior 3 9) returns 11&amp;nbsp; (+ 1 2 8), and (boole 2 11 3) returns 8.&lt;/P&gt;
&lt;P&gt;Go ahead and play with it.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 21:44:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394766#M76932</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2020-03-23T21:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394791#M76933</link>
      <description>&lt;P&gt;Additional to Johns post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/411413"&gt;@dbroad&lt;/a&gt;&amp;nbsp; schrieb:&lt;BR /&gt;
&lt;P&gt;(setvar "osmode" (- (getvar "osmode"))) ;;just toggles the mode.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That would be new for me and my AutoCAD, the toggle for ON/OFF is bit value 16384 as documented&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(defun c:osmodetoggle nil
  (setvar "OSMODE" (boole 6 16384 (getvar "OSMODE")))
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 21:56:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394791#M76933</guid>
      <dc:creator>cadffm</dc:creator>
      <dc:date>2020-03-23T21:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394792#M76934</link>
      <description>Both Doug and you have brightened my day.  I had forgotten about (boole 6&lt;BR /&gt;...)</description>
      <pubDate>Mon, 23 Mar 2020 22:01:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394792#M76934</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2020-03-23T22:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394993#M76935</link>
      <description>&lt;P&gt;Why go down the to hard path just Osnap set it to what you want then type osmode, then get things called a pencil and paper and write the number down, in most cases its only 2 or 3 numbers used, 1, 4, 512, my reset is 47.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 00:38:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9394993#M76935</guid>
      <dc:creator>Sea-Haven</dc:creator>
      <dc:date>2020-03-24T00:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9396057#M76936</link>
      <description>&lt;P&gt;Hello again everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I accepted the solution and the points went to sea.haven but only because the rest of the solutions (although probably more robust) were a little above my paygrade.&amp;nbsp; Thank you so much to everyone that replied though, I took a little from each and it all helps with my study.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The stage I'm at though, I have had to limit editing my lisp files by simply adding ("osmode" x) as the first line of the code and then adding ("osmode" 5823) as the end line to return to my standard snap settings.&amp;nbsp; Not sure I really understood a lot of the other replies but that's entirely a reflection of &lt;EM&gt;my&lt;/EM&gt; limited knowledge.&amp;nbsp; Really appreciate everyones input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using my over-simplified method of changing the snaps, I'm not sure what would happen if I cancelled mid command or there was some other error... no doubt my method will leave me with incorrect snap settings but there was only maybe half a dozen lisp routines that I wanted to specify the snaps on so I'll live with that until I've learned how to factor in errors and such.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, so very much everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brad&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 11:06:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9396057#M76936</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-24T11:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Osmode variable Vs osnap command and its position in lisp routine</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9396115#M76937</link>
      <description>&lt;P&gt;Here you have very often used way to handle osmode on simple (hopefully) example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;Save old&lt;/FONT&gt; osmode, &lt;FONT color="#FF00FF"&gt;set new&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;reset to old&lt;/FONT&gt;. You &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ALWAYS&lt;/FONT&gt;&lt;/STRONG&gt; need to establish the *error* function if you change ANY of system variables to make sure that it resets even in case of &lt;STRONG&gt;ESC&lt;/STRONG&gt;aping/&lt;STRONG&gt;error&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun OMultiple (cur / &lt;FONT color="#FF0000"&gt;*error* osm&lt;/FONT&gt; ent pnt dst)
  
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;  (defun *error* (errmsg)&lt;/STRONG&gt;
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
&lt;STRONG&gt;    (if osm (setvar 'OSMODE osm))&lt;/STRONG&gt;
    (if ent (redraw ent 4))
    (princ)
    )&lt;/FONT&gt;
  
  (if (and (setq ent (ssget "_+.:E:S"))
           (setq ent (ssname ent 0))
           &lt;FONT color="#0000FF"&gt;(setq osm (getvar 'OSMODE))&lt;/FONT&gt; 
           &lt;FONT color="#FF00FF"&gt;(setvar 'OSMODE 0)&lt;/FONT&gt;	
           (not (redraw ent 3))
           )
    (while (setq dst (getdist "\nSpecify offset distance: "))
      (or pnt
          (setq pnt (polar (trans (cdr (assoc 10 (entget ent))) 0 1) (* 1.5 pi) 1)
                dst (abs dst)))
      (command "_.OFFSET" "_E" "_N" "_L" (if cur "_C" "_S") dst ent pnt "")
      (redraw ent 4)
      (redraw (setq ent (entlast)) 3)))

&lt;FONT color="#FF0000"&gt;  (if osm (setvar 'OSMODE osm))&lt;/FONT&gt;
  (if ent (redraw ent 4))
  (princ)
  )

(defun c:OM ()  (OMultiple nil) (princ))
(defun c:OWM () (OMultiple T) 	(princ))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 11:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/osmode-variable-vs-osnap-command-and-its-position-in-lisp/m-p/9396115#M76937</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2020-03-24T11:31:48Z</dc:date>
    </item>
  </channel>
</rss>

