Civil 3D 2014 .NET API has an overloaded Add() method in CorridorCollection class. In this post let’s see how to build a Corridor using the CorridorCollection.Add(string corridorName,
string baselineName,
ObjectId alignmentId,
ObjectId profileId,
string baselineRegionName,
ObjectId assemblyId )
If you want to target the Existing ground surface in the Target Mapping as shown in the screenshot below, then you need to do a trick :) . Thanks to my colleague (Paul Chen) from engineering team for an important hint to achieve this. You need to find out TargetType for each of the SubassemblyTargetInfo object and then set the TargetIds to SurfaceIds as shown in the code snippet below -
// 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];
// Get the first Assembly in the DWG
ObjectId assemblyId = civilDoc.AssemblyCollection[0];
// Create a new Corridor
ObjectId newCorridorId = civilDoc.CorridorCollection.Add("Proposed Corridor", "Proposed Baseline", alignmentId, profileId, "Proposed BaselineRegion", assemblyId);
Corridor corridor = trans.GetObject(newCorridorId, OpenMode.ForWrite) as Corridor;
// Set the Target to existing surface
// GetTargets() Gets the targets information.
// The returned object can be modified and passed to SetTargets()
// to update a corridor's subassembly targets information.
SubassemblyTargetInfoCollection subtargetinfocoll = corridor.GetTargets();
for (int i = 0; i < subtargetinfocoll.Count; i++)
{
SubassemblyTargetInfo subassemblytargetinfo = subtargetinfocoll[i];
if (subassemblytargetinfo.TargetType == SubassemblyLogicalNameType.Surface)
{
subassemblytargetinfo.TargetIds = civilDoc.GetSurfaceIds();
}
}
// update the target information
corridor.SetTargets(subtargetinfocoll);
// now rebuild the corridor
corridor.Rebuild();
trans.Commit();
I used one of the Civil 3D Tutorials DWG file which has prerequisite objects built in it to create the corridor using above code snippet. Hope this is useful to you !