Build a Plugin Command for AutoCAD Civil 3D10 Jul, 2014 By: Andrew G. Roe
Use Visual Studio.NET to customize your Civil 3D experience.
Since its inception, AutoCAD’s open architecture has helped many users customize the software to fit their needs. In more recent years, Autodesk has introduced numerous vertical products, including AutoCAD Civil 3D, Mechanical, and Electrical, leading many to wonder whether further AutoCAD customization would even be necessary. But in practice, no matter how many discipline-specific tools are introduced by Autodesk, CAD users still hunger for more new options and refinements to existing tools. Fortunately for those users, Autodesk has continued to offer customization options such as AutoLISP and .NET for its vertical products, in addition to standard AutoCAD.
In this article, we’ll look at a programming example that you can use to customize Civil 3D. While Civil 3D is primarily geared toward civil engineers and land surveyors, the example demonstrates some key concepts for customizing other Autodesk products, so it is relevant to users in other fields as well. This example will build on the concepts covered in my earlier article, “Create a Plugin for AutoCAD.”
In short, a plugin is a custom command that can be run directly from the AutoCAD environment. The command in this example will obtain some information about intelligent Civil 3D objects in a drawing — specifically, site and alignment objects. In Civil 3D, a site object is used to group collections of other objects that have something in common, such as parcels, alignments, and feature lines that compose a residential subdivision. An alignment object represents road centerlines, pipe networks, and other construction baselines. Civil 3D provides other ways of obtaining site and alignment information, but a custom command allows you to extract this information and manipulate it for your own purposes, such as for a custom report.
As in the article mentioned above, this example uses the Visual Basic.NET programming environment, although you can use Visual C#.NET instead. To complete this exercise, you'll need either Visual Studio.NET or the free Visual Studio Express.
Create a Plugin
1. Start Visual Studio and create a new project by clicking File > New > Project.
3. Click OK to close the New Project dialog box.
4. Click View > Solution Explorer to display the Solution Explorer.
5. Double-click on My Project in the Solution Explorer; the Project Properties screen will appear.
6. Click the References tab on the left.
7. Click the Add button to display the Add Reference dialog box.
8. In the Add Reference dialog box, click the Browse tab, and navigate to where Civil 3D is installed. Select the following files by clicking on one and Ctrl-clicking on the others, in any order: AcCoreMgd.dll, AcDbMgd.dll, AcMgd.dll, AecBaseMgd.dll, and AeccDbMgd.dll. The first three are for accessing standard AutoCAD information and the last two are specific to Civil 3D. (This example is for Civil 3D 2014; references and file names may vary slightly for other versions.)
9. Click OK to close the Add Reference dialog box.
About the Author: Andrew G. Roe
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!