<?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 Simple lisp - can this work better? in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629486#M127603</link>
    <description>&lt;P&gt;I have an autolisp macro&amp;nbsp;for toggling OSMODE and AUTOSNAP programmed into a button on my mouse:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(setq om (getvar "osmode"))(setq as (getvar "autosnap"))(if (= om 0)(setvar "osmode" 4101)(setvar "osmode" 0))(if (= as 39)(setvar "autosnap" 63)(setvar "autosnap" 39))(princ)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works a lot of the time but it's not perfect - if I happen to have autosnap or osmode switched off with a status bar button, the macro toggling doesn't work. Also, I'd like to be able to toggle osmode off in the middle of a command - e.g., start a line with osmode 4101 on to pick an endpoint, then toggle it off to 0, but the command stops when I do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything I can do with this macro to get it working a little more smoothly?&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2016 15:55:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-10-18T15:55:28Z</dc:date>
    <item>
      <title>Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629486#M127603</link>
      <description>&lt;P&gt;I have an autolisp macro&amp;nbsp;for toggling OSMODE and AUTOSNAP programmed into a button on my mouse:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(setq om (getvar "osmode"))(setq as (getvar "autosnap"))(if (= om 0)(setvar "osmode" 4101)(setvar "osmode" 0))(if (= as 39)(setvar "autosnap" 63)(setvar "autosnap" 39))(princ)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works a lot of the time but it's not perfect - if I happen to have autosnap or osmode switched off with a status bar button, the macro toggling doesn't work. Also, I'd like to be able to toggle osmode off in the middle of a command - e.g., start a line with osmode 4101 on to pick an endpoint, then toggle it off to 0, but the command stops when I do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything I can do with this macro to get it working a little more smoothly?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 15:55:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629486#M127603</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-18T15:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629528#M127604</link>
      <description>I forget how to program mouse buttons, but isn't there some suggested syntax like ^C^C(myfunction)?&lt;BR /&gt;&lt;BR /&gt;If so, the ^C^C will probably cancel whatever command is running.</description>
      <pubDate>Tue, 18 Oct 2016 16:11:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629528#M127604</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2016-10-18T16:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629587#M127605</link>
      <description>&lt;P&gt;You might consider using the status bar techniques rather than using 0 and fixed settings for toggles. &amp;nbsp;Negating the osnap and autosnap modes preserves the settings and toggles them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(setvar "osmode" (- (getvar "osmode"))) or something like that. &amp;nbsp;You could always keep the logic checking for 0 and use it to lauch the osnap or autosnap settings dialog.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 16:37:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629587#M127605</guid>
      <dc:creator>dbroad</dc:creator>
      <dc:date>2016-10-18T16:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629732#M127606</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;....&amp;nbsp;if I happen to have autosnap or osmode switched off with a status bar button, the macro toggling doesn't work. Also, I'd like to be able to toggle osmode off in the middle of a command - e.g., start a line with osmode 4101 on to pick an endpoint, then toggle it off to 0, but the command stops when I do this.&amp;nbsp; ....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the case of OSMODE, when you have that 4101 combination set [Endpoint, Center, Extension], if you pick the status-bar icon or hit F3 to turn Osnapping off, it &lt;EM&gt;doesn't&lt;/EM&gt; set&amp;nbsp;OSMODE to 0, but rather adds 16384 to its value, which &lt;EM&gt;retains the mode combination you have&lt;/EM&gt; [which setting it to 0 would not do], but &lt;EM&gt;suppresses&lt;/EM&gt; its application.&amp;nbsp; That's the only way to go if you want to have the same mode combination going when you turn it back on [in which case it &lt;EM&gt;subtracts&lt;/EM&gt; 16384 from it].&amp;nbsp; So if you've done it that way, OSMODE will be 20485, not 0, and your macro will therefore set it to 0.&amp;nbsp; The same would also be true if you have by any other means changed the combination of modes, such as to Endpoint only [OSMODE = 1].&amp;nbsp; And if you turn it off with your mouse-button macro by changing it to&lt;EM&gt; 0&lt;/EM&gt;, then if you try to turn it back on &lt;EM&gt;with F3 or the status-bar icon&lt;/EM&gt;, instead of with the mouse-button macro, it won't come back to 4101, but will call up the dialog box and request some mode(s) to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you want to do is the same thing the icon and F3 do -- add 16384 if it's less than that, or subtract it if it's more.&amp;nbsp; That will maintain whatever mode combination you have.&amp;nbsp; You don't even need a variable to check against, but can do it directly.&amp;nbsp; [It could be that the nil return from the (if) test in some circumstances in your macro is what's stopping commands.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;(setvar 'osmode (boole 6 16384 (getvar 'osmode)))&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some explanation [which some people find helpful, but some do not] of what (boole 6) is doing, look &lt;A href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/laymen-s-explanations-of-logand-logior-and-boole/m-p/2211523/highlight/true#M257885" target="_self"&gt;here&lt;/A&gt;, and find where it starts "The specific operator 6...."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can also be done in a more long-winded but perhaps more understandable way [this is just one of several ways you could go about it]:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(setvar 'osmode (+ (getvar 'osmode) (if (&amp;lt; (getvar 'osmode) 16384) 16384 -16384)))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, with AUTOSNAP, your difference in values is 24, which is toggling Polar Tracking [8] and Object Snap Tracking [16] on and off.&amp;nbsp; You can perform that toggle in the same way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;(setvar 'autosnap (boole 6&amp;nbsp;24 (getvar 'autosnap)))&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will work even if you have some &lt;EM&gt;other&lt;/EM&gt; combination of possibilities for the value, such as if you've turned off Tool Tips [2].&amp;nbsp; Interestingly, if you should have one of the two [Polar Tracking or Object Snap Tracking] &lt;EM&gt;on&lt;/EM&gt; and the other &lt;EM&gt;off&lt;/EM&gt;, rather than your standard of &lt;EM&gt;both&lt;/EM&gt; either on or off together, it will reverse those -- turn off the one that's on and turn on the one that's off.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 17:38:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629732#M127606</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2016-10-18T17:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629771#M127607</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;....&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(setvar "osmode" (- (getvar "osmode"))) or something like that.&amp;nbsp;&amp;nbsp;....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not that way.&amp;nbsp; OSMODE can't have a negative value -- it's not like the color number of a Layer in the result from (tblsearch), that's positive if the Layer's on and negative if it's off.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 17:41:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629771#M127607</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2016-10-18T17:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629933#M127608</link>
      <description>&lt;P&gt;Wow. Incredibly informative and helpful. Thanks, guys!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 18:31:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629933#M127608</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-18T18:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Simple lisp - can this work better?</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629936#M127609</link>
      <description>&lt;P&gt;Oops, thanks Kent. &amp;nbsp;Should have been adding/subtracting from 16384 instead of negating. &amp;nbsp;The diesel form of and is bitwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, this is how the F3 is implemented in the CUI. &amp;nbsp;It uses Diesel. &amp;nbsp;This approach might be more suitable for mouse buttons.&lt;/P&gt;
&lt;PRE&gt;^P'_.osmode $M=$(if,$(and,$(getvar,osmode),16384),$(-,$(getvar,osmode),16384),$(+,$(getvar,osmode),16384)) &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 18:31:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/simple-lisp-can-this-work-better/m-p/6629936#M127609</guid>
      <dc:creator>dbroad</dc:creator>
      <dc:date>2016-10-18T18:31:44Z</dc:date>
    </item>
  </channel>
</rss>

