I am developing an IFC (Industry Foundation Classes) Import/Export Add-In for Civil 3D, which I will publish as open source later this month). The export function works completely fine already. However, I still don’t quite understand how to create objects in Civil 3D using .NET. My add-in is written in C#.
I tried the following, which is a official Autodesk example:// Uses an existing Alignment Style named "Basic" and Label Set Style named "All Labels" (for example, from
// the _AutoCAD Civil 3D (Imperial) NCS.dwt template. This call will fail if the named styles
// don’t exist.
// Uses layer 0, and no site (ObjectId.Null)
ObjectId testAlignmentID = Alignment.Create(doc, "New Alignment", ObjectId.Null, "0", "Basic", "All Labels");
However, whenever I try to run my code, I get the following error message: "Invalid Alignment ID.". My code looks like the following:var civilDatabase = Application.DocumentManager.MdiActiveDocument.Database;
var civilDocument = CivilApplication.ActiveDocument;
using (Transaction civilTransactionManager =
ObjectId civilAlignment = Alignment.Create(civilDocument, "MyName", "" , "0", "Basic", "All Labels");
I also tried to replace the "" that gives the site for the Alignment with null or ObjectID.Null, both does not work and replacing it with ObjectID.Null does even prevent me from compiling.
Anyone knows where that error comes from?
Looking at the documentation for Alignment methods, more specifically the following overload:public static ObjectId Create(
The name of the drawing, layer, style, labelSet or site is invalid. The name of the alignment already exists.
So it seems some of the names are not correct. For a more robust approach, you may list the styles and get a name or objectId from there. For a siteless alignment, you can pass string.empty as siteName parameter.