Civil 3D API in C#: first steps to programming Civil 3D, from your first command to a plugin
What the Civil 3D .NET API is, what you need to program it in C#, your first command step by step, the key objects and the most common errors.
Civil 3D · API · C#
The Civil 3D API is the door few people explain well.
What it is, what to install, how to write your first C# command, the objects you'll use every time, and the errors that show up in week one. With copy-ready code and up-to-date .NET versions.
Why so few people program Civil 3D
There's plenty of material on the Revit API and little on Civil 3D's. It's not that Civil 3D has less to automate: a roadway plan set repeats as much work as a building. It's that the Civil 3D API has more layers, its objects are more complex, and its documentation has fewer examples.
This guide covers the minimum to start right: what it is, what to install, a real first command, and the errors worth knowing before you trip over them.
From code to a button in Civil 3D
Visual Studio project
.NET class library
Autodesk references
AutoCAD + Civil 3D, not copied
C# command
Reads and edits the drawing
NETLOAD or bundle
Loaded in Civil 3D
Civil 3D API in C#, in 6 steps
What the API is, what to install, your first command, the key objects, the week-one errors and how to turn a command into a plugin.
- 01Concept
What the API is
Two layers, AutoCAD and Civil 3D, and the alternatives
- 02Setup
What you need
Visual Studio, your release's .NET and the references
- 03Code
First command
List the alignments in the drawing
- 04API
Key objects
Alignments, surfaces, corridors and points
- 05Errors
Common errors
NETLOAD, Copy Local, Commit and locking
- 06Action
From command to plugin
Button, bundle, error handling and structure
Civil 3D is built on AutoCAD, and so is its API. A Civil 3D program uses two layers:
- The AutoCAD .NET API: documents, transactions, the command line, lines, polylines, blocks and layers.
- The Civil 3D .NET API: the engineering objects: alignments, profiles, surfaces, corridors, sections, COGO points, parcels and pipe networks.
The alternatives, depending on what you need:
- Dynamo, to automate without writing code. Since Civil 3D 2025.1 it ships more than a thousand out-of-the-box nodes; we cover it in 10 Dynamo scripts for Civil 3D.
- Python, inside Dynamo's Python nodes, when the visual nodes fall short.
- The COM API, older, still used by some LISP and VBA routines.
- C# on the .NET API, for production tools the whole office uses. That's the path in this guide.
- Windows with Civil 3D installed. The API only runs inside Civil 3D.
- Visual Studio Community, free, with the .NET desktop development workload.
- The right framework for your release:
| Civil 3D release | Framework |
|---|---|
| 2024 and earlier | .NET Framework 4.8 |
| 2025 and 2026 | .NET 8 |
| 2027 | .NET 10 |
- A class library project, referencing the libraries in the Civil 3D install folder: AcCoreMgd, AcDbMgd and AcMgd from AutoCAD, and AecBaseMgd and AeccDbMgd from Civil 3D.
This command walks through the drawing's alignments and writes each name and length to the command line:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
[assembly: CommandClass(typeof(ZeistDemo.Commands))]
namespace ZeistDemo
{
public class Commands
{
[CommandMethod("ZLISTALIGNMENTS")]
public void ListAlignments()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
CivilDocument civil = CivilApplication.ActiveDocument;
using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
{
foreach (ObjectId id in civil.GetAlignmentIds())
{
var alignment = (Alignment)tr.GetObject(id, OpenMode.ForRead);
ed.WriteMessage($"\n{alignment.Name}: {alignment.Length:F2}");
}
tr.Commit();
}
}
}
}
What each part does:
CommandMethodturns the method into a command you type in Civil 3D.CivilApplication.ActiveDocumentgives access to the Civil 3D objects in the open drawing.GetAlignmentIds()returns the IDs of every alignment.- The transaction opens each alignment for reading, and
Commitcloses it.
To test it: build, open Civil 3D with a drawing that has alignments, type NETLOAD, pick your DLL and run ZLISTALIGNMENTS.
Almost everything starts at the CivilDocument, the Civil 3D document of the open drawing:
| You want to work with | Starting point on CivilDocument |
|---|---|
| Alignments | GetAlignmentIds() |
| Surfaces | GetSurfaceIds() |
| Corridors | CorridorCollection |
| COGO points | CogoPoints |
| Pipe networks | GetPipeNetworkIds() |
| Styles | Styles |
From each alignment you reach its profiles and sample line groups; from each corridor, its baselines and regions. The pattern never changes: get the ID, open the object inside a transaction, then read or modify it.
- "Cannot load assembly" on NETLOAD. The project targets a different framework than your Civil 3D release uses. Check the table in step 2.
- Odd errors when Civil 3D loads or closes. The Autodesk references were left with Copy Local set to Yes.
- Changes aren't saved.
tr.Commit()is missing: an uncommitted transaction is discarded entirely. - eLockViolation. It happens when code runs from your own window instead of a command: lock the document before modifying it.
- Works on your release, not on your colleague's. Every Civil 3D release requires building against its own libraries.
A command that works on your machine isn't a tool yet. For the office to use it you need:
- A button on the Civil 3D top toolbar, instead of a typed command.
- A bundle: the folder in Autodesk's official format that Civil 3D loads at startup.
- Error handling and logging, so a failure never leaves the drawing half-done.
- A layered structure, so an Autodesk release change touches only one part of the code.
We explain it in Revit and Civil 3D add-in development, and if you want to get there faster with AI, in building a Civil 3D plugin with Claude Code.
| Criterion | C# plugin on the API | Dynamo script |
|---|---|---|
| Speed with thousands of objects | High | Variable |
| Custom interface and validation | Yes | Basic |
| Distribution | Installer or bundle for the whole office | A file each person opens |
| Learning curve | Months | Weeks |
| Best for | Daily-use tools | Testing an idea quickly |
Related resources
- The complete guide: Revit and Civil 3D add-in development.
- With AI help: building a Civil 3D plugin with Claude Code.
- Dynamo or C#: which one fits each case.
- What to automate first: Civil 3D automation, the complete guide.
- If you're commissioning one: how much a Revit or Civil 3D add-in costs.
Frequently asked questions about the Civil 3D API
It's Autodesk's official interface for programming Civil 3D. It lets a C# program read and modify alignments, profiles, surfaces, corridors, COGO points and pipe networks. It runs on .NET and on top of the AutoCAD API, which provides documents, transactions and drawing objects.
Technical note: .NET versions follow Autodesk's documentation as of October 2026. Check your release's Developer's Guide before you start.
Keep reading on this topic
Revit and Civil 3D Add-in Development: The Complete Guide (2026)
The complete guide to Revit and Civil 3D add-in development: what add-ins are, what to automate, C# and the Autodesk API, deployment and cost.
Automating Civil 3D: The Complete Guide (2026)
What you can automate in Civil 3D and how: Dynamo, Python, C# and AutoLISP compared, the 15 automations with the best ROI, and which to build first.
How to Build a Civil 3D Plugin with Claude Code Without Being a Programmer: End-to-End 2026 Guide
How to build a Civil 3D plugin with Claude Code without coding experience: architecture, prompts that work, and how to compile and deploy it.
Dynamo vs C# in Civil 3D and Revit: when to use each + automations that save hours
Dynamo or C# for automating Civil 3D and Revit: the real differences, when each one is worth it, and automations that save hours, with examples.