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
