サーフェスから縦断を作成する

縦断は、線形上の標高で構成されるオブジェクトです。各線形には、Alignment.GetProfileIds()·メソッドを使用してアクセスできる縦断のコレクションが含まれます。Profile.CreateFromSurface() メソッドは、新しい縦断を作成し、線形パス上の指定されたサーフェスからその標高情報を取得します。

// Illustrates creating a new profile from a surface
[CommandMethod("ProfileFromSurface")]
public void ProfileFromSurface()
{
    doc = CivilApplication.ActiveDocument;
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        // Ask the user to select an alignment 
        PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment");
        opt.SetRejectMessage("\nObject must be an alignment.\n");
        opt.AddAllowedClass(typeof(Alignment), true);
        ObjectId alignID = ed.GetEntity(opt).ObjectId;
        // get layer id from the alignment
        Alignment oAlignment = ts.GetObject(alignID, OpenMode.ForRead) as Alignment;
        ObjectId layerId = oAlignment.LayerId;
        // get first surface in the document
        ObjectId surfaceId = doc.GetSurfaceIds()[0];
        // get first style in the document
        ObjectId styleId = doc.Styles.ProfileStyles[0];
        // get the first label set style in the document
        ObjectId labelSetId = doc.Styles.LabelSetStyles.ProfileLabelSetStyles[0];
        try
        {
            ObjectId profileId = Profile.CreateFromSurface("My Profile", alignID, surfaceId, layerId, styleId, labelSetId);
            ts.Commit();
        }
        catch (Autodesk.AutoCAD.Runtime.Exception e)
        {
            ed.WriteMessage(e.Message);
        }
        
    }
}