Making new buttons

Making new buttons

gotphish001
Advisor Advisor
910 Views
4 Replies
Message 1 of 5

Making new buttons

gotphish001
Advisor
Advisor

I have a few custom buttons that I made by following some directions or videos or whatever. I want to create a few more. First I would like a button to control osnaphatch. I've been finding that I've been turning off and on if snaps work on hatch recently a lot. It's a pain to type. Can someone show me what to put in the macro field for the button?  Or better yet a  link to some good instructions that explain the syntax of how the macros work so I can just make them myself. 



Nick DiPietro
Cad Manager/Monkey

0 Likes
Accepted solutions (2)
911 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

Would this be what you're looking for?

 

'OSOPTIONS;$M=$(if,$(getvar,OSOPTIONS),0,1);

 

(Found here: https://forums.autodesk.com/t5/autocad-lt-forum/is-there-an-osnaps-ignore-hatch-objects-on-off-tool-...)

Message 3 of 5

David_W_Koch
Mentor
Mentor
Accepted solution

Are you trying to add a button to the ribbon?  I suppose the syntax would be the same if it were for a toolbar as well.

 

There may be more clever ways of programming this, but here is one approach.  I added this as the macro for a command I added to my own custom partial CUIX file and then added a ribbon panel to hold this tool and added the panel to my custom ribbon tab, and it works.  It can even be used mid-command to toggle the ability to snap to hatches while a command is in progress.

 

(if (= 0 (getvar "OSNAPHATCH")) (setvar "OSNAPHATCH" 1) (setvar "OSNAPHATCH" 0))

It is AutoLISP code, with a simple if statement that checks the current value of the OSNAPHATCH system variable (which, curiously, was not listed in the online Help*), and then sets it to 1 if it is 0; otherwise, it sets it to 1.

 

If the main driver here is typing, you could add a command alias of OH for OSNAPHATCH to your acad.pgp file.

 

As for macro syntax, that can be simple (basically, the command-line keystrokes) or quite involved (DIESEL expressions or AutoLISP code).  This article in the AutoCAD Architecture 2018 on-line Help is the top-level article that describes how to create menu macros, and lists many of the subtleties that would not be typed at the command line, but which can make your command macro work better.

 

* - I suppose the "official" system variable for this is OSOPTIONS, where the 1-bit setting matches the OSNAPHATCH setting, but I did not particularly feel like remembering the code to toggle a specific bit of a bit-coded system variable, and since the if statement with OSNAPHATCH worked, I decided that was good enough.


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

Message 4 of 5

gotphish001
Advisor
Advisor

Thanks. I believe both of those will work just different ways. I'll try them out tomorrow if I get a some extra time to devote to tests.



Nick DiPietro
Cad Manager/Monkey

0 Likes
Message 5 of 5

David_W_Koch
Mentor
Mentor

@Anonymous wrote:

Would this be what you're looking for?

 

'OSOPTIONS;$M=$(if,$(getvar,OSOPTIONS),0,1);

 

(Found here: https://forums.autodesk.com/t5/autocad-lt-forum/is-there-an-osnaps-ignore-hatch-objects-on-off-tool-for-autocad/td-p/2940020)


At the time that was written, that would have worked for AutoCAD LT, as it did not support the 2-bit setting (osnaps ignore geometry with negative Z values during use of a dynamic UCS), so the only values that could have been fed to the if statement were 0 (false) or 1 (true).  In full AutoCAD, and verticals built on it, the 2-bit can be set, and there is also now a 4-bit that, when set, will cause object snaps to ignore endpoints of dimension extension lines.

 

While I have not tested it, I would expect that if OSOPTIONS were set to either 2, 4 or 6 (meaning the 1 bit was not set), the value would be set to 0 (leaving the 1 bit still not set) and it would have to be run again to get the value set to 1.  That would also clear the 2 and 4 bits, which may or may not be a problem.  I was never terribly fluent in DIESEL, and it has been years since I have tried to use it.  The AutoLISP statement

(boole 1 1 (getvar "OSOPTIONS"))

will return 1 if the 1-bit is set and 0 if the 1-bit is not set, and could be used in a macro to change the setting of the 1-bit in OSOPTIONS.  I have no idea if there is a DIESEL equivalent of that.

 

*****

 

I should also have stated that the code I posted will not work in AutoCAD LT, as it does not do AutoLISP.  As this is the AutoCAD Architecture forum, I assumed that using AutoLISP was fair game.


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

0 Likes