2.1 Setting Up A .NET Project For Autodesk Civil 3D
2.1 Setting Up A .NET Project For Autodesk Civil 3D
This section describes the basic steps to set up a .NET solution using Visual Studio and the Autodesk Civil 3D managed classes. The
steps are the similar whether you use Microsoft Visual C# .NET or Visual Basic .NET. The example below uses C# in Visual Studio 2010.
Express (free) versions of Visual Studio may look slightly different, but can also be used.
To create a new project that uses the Autodesk Civil 3D managed classes in Microsoft Visual Studio
1. In Visual Studio 2010, create a new class library solution and project.
d. Under Start Options, fill in the Working directory, for example: C:\Program Files\Autodesk Civil 3D
2025\UserDataCache\
5. Implement the IExtensionApplication interface in your main class. Add the Autodesk.AutoCAD.Runtime namespace (which
is where this interface is defined), and IExtensionApplication after your class definition: Visual Studio will provide a code
complete option to implement stubs for the interface. Your code should now look like this:
using System;
using Autodesk.AutoCAD.Runtime;
namespace GettingStarted
{
public class Class1 : IExtensionApplication
{
#region IExtensionApplication Members
#endregion
}
}
You can remove or comment out the default content of these methods. Initialize() is called when your assembly is first
loaded by a NETLOAD command in Autodesk Civil 3D, and can be used for setting up resources, reading configuration files, and
other initialization tasks. Terminate() is called when Autodesk Civil 3D shuts down (there is no NETUNLOAD command to
unload .NET assemblies), and can be used for cleanup to free resources.
6. You are now ready to create a public method that is the target of a CommandMethod attribute. This attribute defines the Autodesk
Civil 3D command that invokes the method. For example:
[CommandMethod("HelloWorld")]
public void HelloWorld()
{
7. Let’s make the method print out a “Hello World” message on the command line. Add the
Autodesk.AutoCAD.ApplicationServices namespace, and add this line to the HelloWorld() method:
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nHello World!\n");
You can now build the assembly and run it. Start Autodesk Civil 3D, and type NETLOAD at the command line. In the Choose .NET
Assembly dialog, browse to your assembly DLL (if you are using the project settings from step 1, this will be GettingStarted.dll).
Type HELLOWORLD at the command line, and you will see the command output:
8. The previous step used functionality from the AutoCAD Application class. Let’s include some functionality specific to the
Autodesk Civil 3D managed classes. First, add two more namespaces: Autodesk.AutoCAD.DatabaseServices and
Autodesk.Civil.ApplicationServices. Then add these lines to obtain the current Civil document, get some basic
information about it, and print the information out:
Open or create a document in Autodesk Civil 3D that contains alignments and sites. When you run the HELLOWORLD command
now, you should see output similar to this:
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
License. Please see the Autodesk Creative Commons FAQ for more information.
© 2025 Autodesk Inc. All rights reserved