Profile object in Civil 3D is a 3D geometric object which joins the Surface elevations along a horizontal Alignment. Profiles are used to visualize the terrain along a route of interest, such as a proposed road, or simply to show how the elevation changes across a particular region.
Profile.CreateFromSurface() method creates a new profile and derives its elevation information from the specified surface along the alignment. Following C# code snippet demonstrates creating a Civil 3D Profile object using .NET API :
// Get the AutoCAD Editor
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//select an Alignment which we will use to create a Profile
PromptEntityOptions selalignment = new PromptEntityOptions("\nSelect an Alignment Object: ");
selalignment.SetRejectMessage("\nOnly Alignment Object is allowed");
selalignment.AddAllowedClass(typeof(Alignment), true);
PromptEntityResult resalignment = ed.GetEntity(selalignment);
if (resalignment.Status != PromptStatus.OK) return;
ObjectId alignmentId = resalignment.ObjectId;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
Alignment alignment = trans.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
// Profile.CreateFromSurface() has 4 overloaded versions
// In this code snippet we will use - public static ObjectId CreateFromSurface(string profileName,
// ObjectId alignmentId, ObjectId surfaceId, ObjectId layerId, ObjectId styleId, ObjectId labelSetId )
// prepare the input parameters
ObjectId layerId = alignment.LayerId;
// let's get the 1st Surface object in the DWG file
ObjectId surfaceId = civilDoc.GetSurfaceIds()[0];
// let's get the 1st Profile style object in the DWG file
ObjectId styleId = civilDoc.Styles.ProfileStyles[0];
// let's get the 1st ProfileLabelSetStyle object in the DWG file
ObjectId labelSetId = civilDoc.Styles.LabelSetStyles.ProfileLabelSetStyles[0];
// Create the Profile Object
ObjectId profileId = Profile.CreateFromSurface("Profile_Created_using_API", alignmentId, surfaceId, layerId, styleId, labelSetId);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("/n Exception message :" + ex.Message);
}
}
As a result of running the custom command containing above code snippet, you would see a new profile (like the following) being added to Civil 3D’s Profiles collection node :