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 =
civilDatabase.TransactionManager.StartTransaction())
{
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?