Build a Plugin Command for AutoCAD Architecture10 Dec, 2015 By: Andrew G. Roe
Use Visual Studio.NET to customize vertical applications.
Following the Dim statements is the code that determines whether the selected entity is an AEC object or not. If not, the user is prompted to select another entity. A transaction statement is included to open the object. A Try…Catch block, discussed in another previous article (“Dealing with Errors in AutoCAD Programs”), includes the code to display the AEC entity data in a message box, or to abort if the entity is not an AEC entity.
Execute the Command
Let’s test the command created in the previous steps. You’ll need to open an Architecture drawing containing at least one AEC object and one standard AutoCAD entity, such as a line.
1. In AutoCAD Architecture, type NetLoad at the Command line, and press Enter.
2. Navigate to the location of the new plugin, and select the DLL file created when the application was built, as shown here. The folder will be located beneath the folder location you specified when you created a new .NET project earlier in this exercise.
3. Click Open to open the selected DLL file.
4. At the AutoCAD Command line, type SelectEntity.
5. Select an entity when prompted. If the entity is an AEC object, the information is displayed in a message box. If not, you will be prompted to select another.
To aid in plugin development, Autodesk provides a plugin wizard, which is described in an online training document, "My First Plug-in Training." Although the wizard is a handy tool, beginning programmers will benefit from building a plugin without its assistance, to better understand the various steps involved.
This example illustrates key concepts of using .NET to develop a custom AutoCAD Architecture plugin. The finished plugin obtains some basic information about a selected object and displays it in a message box for simplicity. In a real application, however, you’d probably want to perform more tasks with this information, or perhaps create your own objects programmatically. You'd also want to provide additional error handling for those inevitable situations where users try to make the program do something it was not intended for. And you can probably think of various ways to further customize this example, but it shows you how to get started with creating plugins for a vertical product.
In future articles, I'll continue to explore additional facets of AutoCAD programming. If you would like to suggest a topic, feel free to send me an e-mail.