線形は通常、既存のサイトと関連付けられることなく、作成されます。各 CivilDocument オブジェクトは、GetSitelessAlignmentIds() メソッドでアクセスできるサイトに関連付けられていない線形のコレクションを独自に持ちます。GetAlignmentIds() メソッドでアクセスできる(非サイトおよびサイトに関連付けられた)すべての線形のコレクションもあります。Alignment.CopyToSite() メソッドで、線形をサイトに移動することができます。Alignment.CopyToSite() を使用して、ObjectId.Null または ““ をサイトとして渡すことで、非サイト線形をサイト線形からコピーすることができます。
Alignment クラスは、新規線形オブジェクトをポリラインから、またはジオメトリ データなしで作成するための Create() メソッドのバージョンを提供します。ジオメトリ データなしで線形を作成するために 2 つのオーバーロードがあります。両方ともドキュメント オブジェクト、および新規線形の名前への参照を取ります。その 1 つは、線形を関連付けるサイト(ObjectId.Null を渡して非サイトの線形を作成します)、線形を作成する画層、線形を適用するためのスタイル、使用するラベル セット スタイルのオブジェクトID を取ります。もう 1 つのオーバーロードはそれらの項目の名前となる文字列を取ります。ここに、ジオメトリ データなしで非サイト線形を作成する簡単な例を示します。
// Uses an existing Alignment Style named "Basic" and Label Set Style named "All Labels" (for example, from // the _AutoCAD Civil 3D (Imperial) NCS.dwt template. This call will fail if the named styles // don't exist. // Uses layer 0, and no site (ObjectId.Null) ObjectId testAlignmentID = Alignment.Create(doc, "New Alignment", ObjectId.Null, "0", "Basic", "All Labels");
ポリラインから線形を作成するための create() メソッドの 2 つのオーバーロードがあります。1 番目は CivilDocument オブジェクト、PolylineOptions オブジェクト(線形の作成元となるポリラインの ID を含む)、新規の線形の名前、線形を作成する画層の ObjectID、線形スタイルの ObjectID、ラベル セット オブジェクトの ObjectID への参照となるとともに、新規線形の ObjectID を返します。2 番目のオーバーロードは同じパラメータを取りますが、画層、線形スタイル、およびラベル セットは ObjectID ではなく、名前によって指定されます。
次のコードは、既存のスタイルを使用して 2D ポリラインから線形を作成します。
[CommandMethod("CreateAlignment")] public void CreateAlignment() { doc = CivilApplication.ActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; // Ask the user to select a polyline to convert to an alignment PromptEntityOptions opt = new PromptEntityOptions("\nSelect a polyline to convert to an Alignment"); opt.SetRejectMessage("\nObject must be a polyline."); opt.AddAllowedClass(typeof(Polyline), false); PromptEntityResult res = ed.GetEntity(opt); // create some polyline options for creating the new alignment PolylineOptions plops = new PolylineOptions(); plops.AddCurvesBetweenTangents = true; plops.EraseExistingEntities = true; plops.PlineId = res.ObjectId; // uses an existing Alignment Style and Label Set Style named "Basic" (for example, from // the Civil 3D (Imperial) NCS Base.dwt template. This call will fail if the named styles // don't exist. ObjectId testAlignmentID = Alignment.Create(doc, plops, "New Alignment", "0", "Standard", "Standard"); }
線形は、既存の線形のレイアウトに基づいて作成することもできます。Alignment::CreateOffsetAlignment() メソッドは、一定のオフセットで新しい線形を作成し、元の線形と同じ親サイトに追加します。新しい線形は、元の線形と同じ名前(括弧で囲んだ番号が後に付く)と同じスタイルを使用しますが、測点ラベル、ブレーキ測点、設計速度は継承しません。
[CommandMethod("CreateOffsetAlignment")] public void CreateOffsetAlignment() { 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 to create a new offset alignment from PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment"); opt.SetRejectMessage("\nObject must be an alignment."); opt.AddAllowedClass(typeof(Alignment), false); ObjectId alignID = ed.GetEntity(opt).ObjectId; Alignment align = ts.GetObject(alignID, OpenMode.ForRead) as Alignment; // Creates a new alignment with an offset of 10: ObjectId offsetAlignmentID = align.CreateOffsetAlignment(10.0); } }