civil3d_execute
Run C# code in Civil 3D with write access to modify drawings, executing inside a committed transaction and returning JSON results.
Instructions
Execute C# code in Civil 3D with write access. The code runs inside a committed transaction. Available globals: Document, CivilDoc, Database, Transaction, Editor. All Civil 3D namespaces are auto-imported. Return a value to get results back as JSON. Use this for operations that MODIFY the drawing (create, edit, delete objects). expectedDrawing must come from a prior read-only identity query. To persist the drawing file, set saveDrawing=true; do not call Database.SaveAs or queue QSAVE from the C# code.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | C# code to execute. Has access to Document, CivilDoc, Database, Transaction, Editor. Example: var id = TinSurface.Create(Database, "MySurface"); return new { success = true }; | |
| description | No | Optional human-readable summary; excluded from operation audit logs. | |
| saveDrawing | No | When true, save the currently named DWG after the write transaction commits and wait for completion. Use this instead of Database.SaveAs or Document.SendStringToExecute("QSAVE") in code. An unsaved drawing must first be named in Civil 3D. | |
| idempotencyKey | No | Optional opaque session key. Reuse it only to manually reconcile an uncertain outcome; use a new key for an intentional new write. | |
| expectedDrawing | Yes | Expected active drawing identity checked immediately before Civil API access. |