Create custom AutoCAD commands and toolbars



April 5, 2011

By: Emilio Valentin



From the Trenches: Looking for an easier way to access your custom LISP routines? This user-written tutorial will walk you through the process of creating the toolbar.

Have you ever needed to create your own toolbar or command in AutoCAD? You may have been using custom LISP routines for years and need to add them to your current version of AutoCAD. Sometimes a toolbar can be an easier way to access these custom routines – and creating one is a simple process. (Note: This tutorial was created with AutoCAD 2009, but the process is nearly identical in newer versions.)

Almost all commands will now allow binding an icon. So, to start, we need the icons and a folder to store them. Icons should be in BMP format, and 64 x 64 pixels will work fine. You can use Microsoft Paint to create them. As for the folder, check out Tools > Options > Files to see where AutoCAD looks for icons.

Next is the folder where your LISP files or scripts are located. These must be in the media path and can be on a local drive or network location if you wish to share them (same goes for icons). Separating them from the Program Files/AutoCAD directory makes it easier to upgrade or repair, as you don’t have to worry about them being removed during an uninstall.

Once your icons and folders are ready, boot into the Custom User Interface (CUI): type CUI in the command line to open it. First create a new CUIX file (again, this is one of the safe ways to prevent your custom toolbars/ribbons/etc from being deleted and allow sharing). Expand the CUI and click on the Transfer tab. On the right side, click the icon to create a new customization file, choose Save As, provide a name for the CUIX, and set the location to the folder you listed in your options support files.

After creating the file, go back to the left and click on the Customize tab. All you did was create an empty CUIX file; now we need to load it and add our toolbars or ribbon tabs/panels. Scroll down to Partial CUI Files in the tree on the left, right-click, choose Load Partial Customization File, and navigate to the file you created.

Once you’ve loaded it, the partial CUIX should be shown in the dropdown at the top – if not, skip to that one. This is where we want to create your custom toolbar. Expand the toolbar section tree, right-click the toolbar and select New Toolbar.

The right side of the CUI changes its display and allows you to name the tool. The default name is “Toolbar1”; rename it by tapping on the name. You can leave the rest of the options as default settings.

Now we just have to create the commands to add to our toolbar. In the lower section of the CUI are the commands for the custom CUIX file. Create a new order by selecting the icon with a star and an orange sun on it.

As the display on the right changes, we’ll start filling in our parameters for that command. Give the custom command a name and define the macro to run it. This can be the command to run a LISP routine, or you can create your own macro. Next, select the image(s) to use for this command.

We now have a complete command in the list of commands; the next step is to add this command to the toolbar. Do this simply by selecting it and dragging it to the toolbar above.

Create the rest of your commands and drag them to your toolbar as well. When you’re done, select All Customization Files from the drop-down list. Highlight your current workspace in the tree view on the left, then on the right expand the toolbar tree and you should see your new toolbar.

If you don’t see it, you can load this toolbar into the workspace by clicking the Customize Workspace button on the right, then expanding the partial CUI files on the left, expanding your custom CUIX and checking the box for the tool.

When you’re done, click Apply, then OK to close the CUI, and you should have your new toolbars. These same steps will also allow you to create a new ribbon tab and panel with your custom commands. Remember: a command goes in a panel, and a panel goes in a ribbon tab. First create the tab, followed by the panel; place the controls on the panel, then drag the panel to the tab.