[update: working on a macro library - http://www.cadnoob.com/CADnoobJoom/index.php/tutorials-how-to/cadnoob-macro-bible]
I've got a shit tone of drawings to process and there is a pretty mundane set of tasks i need to do to them all. So I've decided to look into macros. AutoCAD is kinda goofey (to me) when it comes to macros. In general i know that macros are some sort of tool that you use to make tasks, especially repeated tasks, easier. I am mostly familiar with macros in Excel where the language you use to create macros is the same language you use to customize scripts and everything else (..well mostly). This is not the case with CAD. There are several ways to do macro like things and I am confused as all hell what the difference is between them. But as AutoCAD is a robust program they always seem to have 60 different ways to do everything.
I've dabbled in Lisp and so im kind of familiar with what's going on there, but I want to create the other kind of macro... the one that is best described as the one you type with a preceding ^C^C. As far as I can tell these are the one true macro.. one syntax to rule them all... at least if they want to be called a macro. What comes after the ^C^C looks just to be command line calls separated by semicolons. [note: the ^C^C is the equivalent to escaping the current command. If you are like me you hit the escape key with something like a 30:1 ratio compared to the other keys. In fact left hand resting position has my middle finger resting on the all powerful Esc]
So lets jump in a break some shit. To start off you need a way to call the command. In typical noob fashion I tried to type ^C^C followed by a command in the command line and it gave me crap.
So what we need to do is create the command and stick it somewhere we can call it. When I first ventured out I created a ribbon and stuck it there, but this is terrible place for learning purposes as it is much easier to change the script if you place it in the tool palette.
Step 1. Whip out the tool palettes.
you can find the tool palettes in the 'View' ribbon. Or you can type the command TOOLPALETTES. This should bring up the pallet below. If you are not into using palettes this might change your mind about them.
Next you will want to create a new palette by clicking on the properties button on the tool palette window and then select new palette. Name it what ever you want, but I've got donkey balls trade marked so don't do anything stupid. Once you create your new palette you may have to click on the all palettes option at the bottom of the options menu you clicked on to create the new palette.
Step 2. Put your command on there.
Sound easy right? To do this you right click on the empty space that is your tooless palette. In the menu that pops up click Customize Commands...
You will have to click the little star with the asterisk on it to create a new command. This will create a command [I think it defaults to Command1 or what ever sequential number your custom commands are on]. You can rename, delete and a few other things from this menu. Once you have your command [don't close that window] you can click and drag your command to you new custom tool palette. Then click ok.
Step 3. Make it mean something
Right click on your custom command and click properties and this will bring up the Tool Properties window and you will notice our magical ^C^C. So just go right in there and type in a command and voila you have created a macro... or at least a real simple one.
Step 4. My shit still doesn't work...
Now the Voodoo of syntax and ignorance takes over. To actually make the macros worth your time often you will need to automate 'complex' commands, but for me the problem is that i have no idea how to make it fully automatic. Here is a neat little secret to help you know what elements of the command you will have to include in your macro. Some commands its easy to see what you will need to include in the code. For instance if you type in LINE in the command you are prompted for coordinates, so if you needed to macro a line command it would look something like this:
[I added the last ^C to close out the command]. But if you have a command like PURGE you don't want to have to click on stuff in the popup GUI. So can you make these commands automatic? Yep! If you type your command in the command line with a preceding "-" it will suppress the popup window and you will be prompted on the command line for the options. Write down the options as you select them to complete the operation and then add them to your macro. Don't forget to separate each option with a semicolon (;). From what I understand the semicolon is the equivalent of hitting enter. So if I wanted to purge the drawing my macro would like this:
[Note: you must remember to include the "-" to suppress the dialog, other wise a popup window will show up.]
Step 5. So... drawing a line is supposed to be cool?
So yea, no big deal, its not that hard to draw a line or purge a drawing why do I need macros? The reason why the are bad ass is cause you can stack them. The following macro will draw a box, purge the drawing, change the layer to 0 and zoom extents with ONE click BOOM! that's cool. The things you can throw into these macros has the potential to completely change your workflow.
Rumor has it you can even call scripts and lisp with these so it really unleashes so raw power of CAD. Hopefully I can get over some noobness and put together an advanced macro article on day but until then go forth and marco!