← Back to blog
Civil 3DCivil 3D APIC#.NETCivil 3D pluginsBIM automation

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.

Zeist··8 min read
Share on LinkedInCivil 3D API in C#: first steps to programming Civil 3D, from your first command to a plugin

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.

  1. 01Concept

    What the API is

    Two layers, AutoCAD and Civil 3D, and the alternatives

  2. 02Setup

    What you need

    Visual Studio, your release's .NET and the references

  3. 03Code

    First command

    List the alignments in the drawing

  4. 04API

    Key objects

    Alignments, surfaces, corridors and points

  5. 05Errors

    Common errors

    NETLOAD, Copy Local, Commit and locking

  6. 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.
  1. Windows with Civil 3D installed. The API only runs inside Civil 3D.
  2. Visual Studio Community, free, with the .NET desktop development workload.
  3. The right framework for your release:
Civil 3D releaseFramework
2024 and earlier.NET Framework 4.8
2025 and 2026.NET 8
2027.NET 10
  1. 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:

  • CommandMethod turns the method into a command you type in Civil 3D.
  • CivilApplication.ActiveDocument gives 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 Commit closes 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 withStarting point on CivilDocument
AlignmentsGetAlignmentIds()
SurfacesGetSurfaceIds()
CorridorsCorridorCollection
COGO pointsCogoPoints
Pipe networksGetPipeNetworkIds()
StylesStyles

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.

CriterionC# plugin on the APIDynamo script
Speed with thousands of objectsHighVariable
Custom interface and validationYesBasic
DistributionInstaller or bundle for the whole officeA file each person opens
Learning curveMonthsWeeks
Best forDaily-use toolsTesting an idea quickly

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.

Talk to an engineerReply today · No commitment