Alignment::Entities コレクション内の各図形は Alignment::AlignmentEntity クラスから派生した型になります。AlignmentEntity.EntityType プロパティをチェックすることで、各図形のタイプを調べ、適切なタイプの参照をキャストできます。
次の例では、線形内のすべての図形をループし、図形のタイプを特定して、そのプロパティの 1 つを出力します。
[CommandMethod("EntityProperties")] public void EntityProperties() { 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 get info about 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; int i = 0; // iterate through each Entity and check its type foreach (AlignmentEntity myAe in align.Entities){ i++; String msg = ""; switch (myAe.EntityType) { case AlignmentEntityType.Arc: AlignmentArc myArc = myAe as AlignmentArc; msg = String.Format("Entity{0} is an Arc, length: {1}\n", i, myArc.Length); break; case AlignmentEntityType.Spiral: AlignmentSpiral mySpiral = myAe as AlignmentSpiral; msg = String.Format("Entity{0} is a Spiral, length: {1}\n", i, mySpiral.Length); break; // we could detect other entity types as well, such as // Tangent, SpiralCurve, SpiralSpiral, etc. default: msg = String.Format("Entity{0} is not a spiral or arc.\n", i); break; } // write out the Entity information ed.WriteMessage(msg); } } }
各図形は、その AlignmentEntity.EntityId プロパティに含まれる識別番号を持ちます。各図形は線形内における前後の図形の番号を認識します。また、AlignmentEntityCollection.EntityAtId() メソッドを使用することで識別番号で特定の図形にアクセスできます。