Create Custom AutoCAD Commands and Toolbars6 Apr, 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 toolbar creation process.
Have you ever needed to create your own toolbar or command in AutoCAD? Maybe you have some custom LISP routines you been using for years, and you need to add them to your current version of AutoCAD. Sometimes a toolbar may be an easier way to get to those custom routines — and creating one is a simple process. (Note: This tutorial was created with AutoCAD 2009, but the process is virtually identical through more recent releases.)
Almost all commands will now allow linking an icon. So to start, we need the icons, and a folder to store them in. The icons must 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 the icons.
Next is the folder where your LISP files or scripts are located. These need to be in the support path, and can be on a local drive or network location if you want to share them (the same goes for the icons). Keeping them separate from the program files/AutoCAD directory makes it easier to upgrade or do a repair, because you don't have to worry about them being deleted during an uninstall.
Once your icons and folders are ready, start in the Customize 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 keep your custom toolbars/ribbons/etc. from being deleted and to allow sharing). Expand the CUI and click on the Transfer tab. On the right side, click on the icon to create a new Customization file, choose Save As, provide a name for the CUIX, and set the location in the folder you have listed in your Options Support files.
After you create 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 the Partial CUI Files in the tree at the left, right-click, choose Load Partial Customization File, and browse to the file you created.
Once you load it, the partial CUIX should be displayed in the pull-down list at the top — if not, switch to it. This is where we want to create your custom toolbar. Expand the tree for the toolbar section, right-click on 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 typing over the name. You can leave the rest of the options as the default settings.
Now we just need to create the commands to add to our toolbar. At the bottom section of the CUI are the commands for the custom CUIX file. Create a new command by selecting the icon with a star and an orange sun on it.
As the right-side display changes, we'll start to fill in our parameters for that command. Provide a name for the custom command, and set 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 that command.
Now we have a complete command in the command list; the next step is to add that command to the toolbar. Do so by simply selecting and dragging it to the toolbar above it.
Create the rest of your commands, and drag those up to your toolbar as well. When you're finished, select All Customization Files from the pull-down list. Highlight your current workspace in the tree on the left, then on the right side expand the tree for the toolbar, and you should see your new toolbar.
If you don't see it, you can load that toolbar into the workspace by clicking on the Customize Workspace button on the right, then expanding the Partial CUI Files on the left, expanding your custom CUIX, and placing a checkmark in the box for the tool.
When you are done, click Apply, then OK to close the CUI, and you should have your new toolbars. These same steps will allow you to create a new ribbon tab and panel with your custom commands as well. Just remember: a command goes in a panel, and a panel goes in a tab of the ribbon. Create the tab first, followed by the panel; place the commands on the panel, then drag the panel to the tab.
Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's free Tips & Tools Weekly e-newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!