Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One place where you can save yourself some clicks is by creating a macro-enabled tool. Macros automate the way a command works, entering your favorite options automatically. In this lesson we're going to learn how to create a macro-enabled tool. On my screen I have a drawing of a plat of survey and I would like to purge this drawing and remove all of the unnecessary information. Let's see how many steps that is. First, I'll open the Application menu, then I'll come down to Drawing Utilities, and I'll select Purge.
I will then click Purge All, I'll select Purge all items, and I'll click Close. Now while that wasn't horribly time consuming, it was several clicks. Wouldn't it be nice if we could create a button that would purge the entire drawing in a single click? Well, this is where macros come in. A macro is nothing more than a line of text. Essentially, you create a text string that mimics what you would type at the command line, and then you create a button that plays back that text. So let's try that. I'm going to click on Undo to restore my purged items.
Since macros are text-based, they don't work too well with dialog boxes. So to create a macro for the Purge command, I'm going to run the text-based version of Purge. To do that, I'll type -purge and I'll press Enter. Notice I'm getting all of the same options. They are just available down here at the command line. As a side note, try putting a dash in front of other commands that invoke a dialog box. Commands like plot, or layer, or insert and you'll find that nearly every command can be driven using only text. All right! So I launched Purge and I pressed Enter.
Next, I'm going to press the letter A, because I'd like to purge all types of objects, and I'll press Enter. At the Enter name(s) to purge prompt, I'll press Enter because I'd like to purge all names. Finally, at the Verify each name to be purged prompt, I'll type the letter N and then I'll press Enter. As you can see, we can drive the entire command using only the keys on our keyboard. So the macros that we create will essentially match the buttons I just pressed. Once again I'm going to click Undo to bring back my purged information.
To create my macro, I'm going to launch the CUI command. I'll do that by clicking the Manage tab and then I'll select CUI. In the Command List area, I'll click the Create a new command icon. I can see my new command right down here in the Command List. Over here on the right, is a form that I can fill out related to this command. I'm going to start with the name. Let's call this purgeall. I will then click in the Description area and I will type in a description.
We'll say purges dwg in 1 click. This is what we'll see in the rollover tooltip when we hover over the icon. Next, I'll click in the Macro. This is our text string. Notice it already has some text in here, ^C^C. This essentially means Cancel, Cancel. This ensures that when I run my new command, AutoCAD will cancel any existing command that may already be running. I will then type my text string. I'll start with an underscore to let AutoCAD know I'm entering a command.
I will then type -purge, the same thing I tied to the command line, and now I have to simulate an Enter or a Return. There are two ways we can do this. I can use a space, or let me take that away. I can use the semicolon. The semicolon is probably the best choice, because if you have several enters in a row, they are visual. I can see several semicolons. It's easy to see multiple semicolons. After I launched the command and pressed Enter, I then type the letter A, because I want it to purge all objects, and I pressed Enter.
So I'll add another Semicolon. At this point, I pressed Enter again to accept the Asterix for the names to purge. Then AutoCAD asked me to verify each name, in which case I typed N and then I pressed Enter again. So this text string represents our macro for my one-click purge command. Now that I'm finished with my macro, let's assign an icon to this command. I can grab an icon from this list at the top. I'll pull this slider down and I'm going to select the standard purge icon to start with.
I will then come over here and click Edit and I can make changes to this image. Now this is the Button Editor. This is a very simplistic image editing tool. I have a couple of color choices over here on the left. I can freehand draw. I can draw some straight lines or circles. I have an erase tool. I can clear my icon. If I put a check in this box, I can display a grid that shows me the pixels in the icon. If you'd like to create really artistic icons, you can always create them in another application like Photoshop and you can click this Import button to bring them in.
I'm going to select the color red, and I am just going to create a big letter A here, for all. When I'm finished, I'll click Export and AutoCAD will take me into the default custom icons folder on my hard drive. I'm going to call my icon purgeall. Notice that AutoCAD is saving this as a BMP. Let's click Save. That default folder is the best place to save your icons, because eventually when you migrate your AutoCAD settings to the next version of AutoCAD, AutoCAD is going to look in that custom icons folder for any of your special symbols.
Now that I'm finished with my icon, I'll click Close, and AutoCAD is asking if I want to save changes. I'm going to click No, because I don't want to overwrite to the original icon image. Now let's assign our new icon symbols to the command. I'll do that down here in the Images area. As you can see, it's currently looking at the standard purge icon. Let me click in this field and I'll click the ellipses button, which takes me right back to that standard Icons folder. I'll select purgeall. Then, I'll click Open.
For the Large image, we'll use the same icon. Now that my command is finished, I'm going to click, hold, and drag, and I'll drop this up here in the Quick Access Toolbar. I can also drag this into a Ribbon panel like we saw in the previous lesson. When I'm finished, I'll come down and click OK. All right! Let's try out the new button. If I hover over this, so I can see it will purge the drawing in one click. Let me click the icon and that's it. The drawing has been purged. If I press F2 to bring up my command line history, let's roll up here.
I can see that AutoCAD launched the purge command and pressed Enter. It then typed the letter A for me and pressed Enter. It pressed Enter again at the asterix. Typed the letter N, and pressed Enter, and then it purged out all of the unnecessary information. Using this technique, we can create a custom automated macro for nearly any command. Now I'd like to do one more thing. Let's look at how we could create a macro that allows me to select a point on screen. For instance I'm going to move up and launch the Rectangle command.
When I launch Rectangle, the first thing AutoCAD asks me is to specify a corner point. So I'm going to click on screen. After I pick my point, 99% of the time I used the dimensions option. I type the letter D and hit Enter. I will then enter my dimensions. I will make this a length of 20 and a width of 5 and then I'll click onscreen to finish my rectangle. I would like to create a macro such that when I launch the Rectangle command, it will enter the dimensions option for me. Let's try that.
Once again, I'm going to return to the CUI. I'll click Manage, and then CUI. In the Command List area, I'll click Create new command. Then in the Properties area, I will give my command a name. I'll call this rectangdim. In the Description area, I will type "creates rectangles via dimensions." Now let's take a look at the macro. Cancel, Cancel. I'm going to keep that.
I'll enter an underscore and then I'll type rectang. This is the physical command that you would type at the command line to launch the Rectangle command. In fact, if you have any question about what the text version is for any command, simply launch it by clicking the icon, and take a look at the command line. For instance, we just launched CUI. You can see that we could also access that by typing cui at the command line. Now after I launch the Rectangle command, I press Enter. Then I have to pick a point on screen to have AutoCAD pause the macro such that I can pick a coordinate.
I'm going to use a backslash. After I pick my point, I'd like AutoCAD to enter the d option for dimensions, and then I'll press Enter. So I'll add another semicolon. Once again, let's grab an icon for our new command. I'm going to drag this down. You can select any icon you wish. I'm going to choose the standard rectangle command and I'll click Edit. Once again, I'm going to use the color red and I am just going to freehand draw a big D for dimensions.
That's good enough. When I'm finished, I'll click Export and we'll save this in the custom icons folder. Finally, I'll click Close and then I'll select No, because I don't want to overwrite the original icon. I will then assign this icon to my command using the ellipses button, and I will do that for both the small and the large image. Now that my command is finished, I will click, hold, and drag this command up to the Quick Access Toolbar and I'll click OK.
Okay, let's try it out. I will move up and click Rectangle. I will pick a point on screen and notice AutoCAD is asking me for my length. It entered the d for me automatically. I'm going to press Enter to accept the defaults and then I'll pick again to finish my rectangle. As you can see by creating macro- enabled tools, you can automate many of your repeated keystrokes, which over the course of the day can save you valuable time. Don't stop here either. See if you can link two or three commands together within a single macro.
Get unlimited access to all courses for just $25/month.Become a member
109 Video lessons · 11821 Viewers
102 Video lessons · 8872 Viewers
83 Video lessons · 13093 Viewers
56 Video lessons · 15432 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.