Dynamically add Entities to an Aligment

Dynamically add Entities to an Aligment

f.rampf
Enthusiast Enthusiast
731 Views
3 Replies
Message 1 of 4

Dynamically add Entities to an Aligment

f.rampf
Enthusiast
Enthusiast

I am dynamically creating alignments in Civil 3D based on some self-defined objects. These objects contain all the information needed to create an alignment as well as the respective entities such as lines, arcs, and spirals.

In a first step I create my alignment (This alignment perfectly shows in Civil 3D):

 

 

var civilDatabase = Application.DocumentManager.MdiActiveDocument.Database;
var civilDocument = CivilApplication.ActiveDocument;

var civilAlignmentId = Alignment.Create("My Aligment (1)", "", "C-ROAD", "Proposed", "All Labels");

 

Then I open the transaction manager and pass my priorly created alignment ID to get the actual alignment:

 

 

using (Transaction civilTransactionManager = civilDatabase.TransactionManager.StartTransaction())
{
var civilAlignment = (Alignment)civilTransactionManager.GetObject(civilAlignmentId, OpenMode.ForWrite);

 

In the following steps, I want to add the entities to the alignment. Because this did not work, I tried using the example from https://knowledge.autodesk.com/support/autocad-civil-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/... to just create one simple entity looking like the following:

 

Int32 previousEntityId = 0;
Point3d startPoint = new Point3d(8800.7906, 13098.1946, 0.0000);
Point3d middlePoint = new Point3d(8841.9624, 13108.6382, 0.0000);
Point3d endPoint = new Point3d(8874.2664, 13089.3333, 0.0000);
AlignmentArc retVal = myAlignment.Entities.AddFixedCurve(previousEntityId, startPoint, middlePoint, endPoint);

However, this is when I am failing. The arc never shows in Civil 3D. I also tried the same with a line, but it does not show either. Am I missing a step here?

 

Regards,

Felix

0 Likes
Accepted solutions (1)
732 Views
3 Replies
Replies (3)
Message 2 of 4

Jeff_M
Consultant
Consultant
Accepted solution
Are you committing the transaction?
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 4

f.rampf
Enthusiast
Enthusiast

I did not do that... After adding the following line:

 

 

civilTransactionManager.Commit();

Everything works fine and the Line shows in Civil 3D. Thank you very much, Jeff, you are my life saver! And please apologize for my lack of knowledge of the .net civil 3d API and this fairly obvious question resulting from that.

 

 

Best regards,

Felix

0 Likes
Message 4 of 4

Jeff_M
Consultant
Consultant
This is a common omission when learning the AutoCAD (not just C3D) API. If you don't Commit, then the Transaction is Disposed/Aborted, thus acting like Undo inside your code. I can't recall how many times I did this when I first started, but it was more than just a few... 🙂
Jeff_M, also a frequent Swamper
EESignature
0 Likes