After the quick summary of new Corridor APIs available on Civil 3D 2014, this post show how create a corridor and add a baseline with alignment and profile.
Unlike other previous APIs, like Alignment and Surface, where the Create method was at the class, with Alignment.Create and TinSurface.Create respectively, to create a corridor we need to access the collection under CivilDocument and then call Add method. Like other APIs, this method returns the ObjectId of the newly created Corridor.
The following quick sample demonstrate it. Note that the same idea applies to Baseline – access the collection and call its Add method.
[CommandMethod("testCreateCorridor")]
public static void CmdCreateCorridor()
{
Database db = Application.DocumentManager.
MdiActiveDocument.Database;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = db.
TransactionManager.StartTransaction())
{
// Create a new Corridor
ObjectId newCorridorId = civilDoc.
CorridorCollection.Add("Corridor 1");
Corridor corridor = trans.GetObject(
newCorridorId, OpenMode.ForWrite) as Corridor;
// Get the first alignment of this drawing
ObjectId alignmentId = civilDoc.GetAlignmentIds()[0];
Alignment alignment = trans.GetObject(
alignmentId, OpenMode.ForRead) as Alignment;
// Get the first profile of this alignment
ObjectId profileId = alignment.GetProfileIds()[0];
// Create the baseline
Baseline baseline = corridor.Baselines.Add(
"New Baseline", alignmentId, profileId);
}
}