Add Your Plugin to an AutoCAD Menu26 Sep, 2013 By: Andrew G. Roe
Load and run a plugin the quick way — without typing.
In my previous article about AutoCAD programming, we learned how to use the .NET programming environment to create an AutoCAD plugin — a custom command that can be run directly from the AutoCAD environment. The plugin included a custom command that created a circle object and some accompanying text simultaneously. We used AutoCAD’s NetLoad command to load the plugin, and we typed the custom command name (CreateMyCircle) at the Command line to run it.
Although that approach served the purpose of demonstrating plugins, in reality most AutoCAD users would rather not expend time and effort typing in the Command line. Let’s look at how we can use some of AutoCAD’s built-in customization tools to add our plugin to one of AutoCAD’s pull-down menus. We will create an AutoCAD script file to set some key parameters for our custom command, and we will use AutoCAD’s Customize User Interface (CUI) dialog box to assign our custom command to a menu.
Create a Script
In AutoCAD, a script is simply a text file containing a sequence of AutoCAD instructions. We can create a text file as follows:
1. Using a text editor such as Notepad, type the following lines:
Filedia 0 Netload "c:\Scripts\MyCircleCommand.dll"
Make sure to include a space at the end of the second line.
2. Save the file as MyCircleScript.scr in a location of your choice. For simplicity, I’ve put it in a folder directly under my root directory called Scripts, as shown below. I’ve also saved the plugin called MyCircleCommand.dll (created in the previous article) in the same location. You can choose a different save location to fit your needs if, for example, you have other macros saved in a specific folder.
(Note: You may need to adjust some settings to see file extensions in Windows. If you do not see the SCR file extension in Windows 7, go to Control Panel, select Appearance and Personalization > Folder Options and click the View tab. Uncheck the item called Hide extensions for known file types and click OK.)
The script file sets the AutoCAD variable called Filedia to 0. This suppresses dialog boxes and directs all user input to the Command line. We’ll set it back to 1, the default value, in our custom command to enable dialog boxes. The second line in the script executes AutoCAD’s Netload command to load the plugin.