Sample Code (.NET)


This guide and the ObjectARX SDK together contain a large number of sample projects, subroutines, and functions that demonstrate the use of the classes, structures, methods, properties, and events that make up the AutoCAD .NET API.

You can also find sample projects that demonstrate some of the aspects of the AutoCAD .NET API on the Autodesk website at These sample projects show a wide range of functionality, from working with database objects to working with sheet sets.

Many of these samples show how to combine various aspects of the VB.NET and C# programming languages with the power of the AutoCAD .NET API to create custom applications.

Additionally, sample code in the help documentation related to the AutoCAD .NET API can be copied to the clipboard and pasted directly into an open code editor window in Microsoft Visual Studio, and then built and loaded in AutoCAD. At the top of most code samples in this guide are the namespaces that are required for that particular sample. Add those that are needed to top of the code module in your project.

NoteThe AutoCAD .NET samples in the help documentation contain limited error handling and disposing of objects to keep the concepts simple and easy to read. You should apply additional error handling and checking when using any sample code in your project.


To run the sample code from the Help files

  1. In Microsoft Visual Studio, open a code editor window, add the proper namespaces and define a class if one does not already exist.
  2. Copy the sample code from the Help file and paste the copied code into the defined class.
  3. In Microsoft Visual Studio, click Build menu Build <Project>.
  4. In AutoCAD, at the Command prompt, enter netload and press Enter.
  5. In the Choose .NET Assembly dialog box, select the built assembly file. Click Open.
  6. At the Command prompt, enter the name of the command defined inside the CommandMethod attribute.