@Anonymous wrote:
.... 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. ....
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 doesn't set OSMODE to 0, but rather adds 16384 to its value, which retains the mode combination you have [which setting it to 0 would not do], but suppresses its application. 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 subtracts 16384 from it]. So if you've done it that way, OSMODE will be 20485, not 0, and your macro will therefore set it to 0. 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]. And if you turn it off with your mouse-button macro by changing it to 0, then if you try to turn it back on with F3 or the status-bar icon, 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.
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. That will maintain whatever mode combination you have. You don't even need a variable to check against, but can do it directly. [It could be that the nil return from the (if) test in some circumstances in your macro is what's stopping commands.]
(setvar 'osmode (boole 6 16384 (getvar 'osmode)))
For some explanation [which some people find helpful, but some do not] of what (boole 6) is doing, look here, and find where it starts "The specific operator 6...."
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]:
(setvar 'osmode (+ (getvar 'osmode) (if (< (getvar 'osmode) 16384) 16384 -16384)))
Similarly, with AUTOSNAP, your difference in values is 24, which is toggling Polar Tracking [8] and Object Snap Tracking [16] on and off. You can perform that toggle in the same way:
(setvar 'autosnap (boole 6 24 (getvar 'autosnap)))
That will work even if you have some other combination of possibilities for the value, such as if you've turned off Tool Tips [2]. Interestingly, if you should have one of the two [Polar Tracking or Object Snap Tracking] on and the other off, rather than your standard of both either on or off together, it will reverse those -- turn off the one that's on and turn on the one that's off.
Kent Cooper, AIA