サーフェスを定義しているリンク コードおよび計画線コードを追加または削除することにより、CorridorSurface オブジェクトを修正することができます。リンク コードは AddLinkCode () メソッドで追加し、計画線コードは、AddFeatureLineCode () メソッドで追加します。削除するには、それぞれ RemoveLinkCode() および RemoveFeatureLineCode() を使用します。これらのメソッドには、コード名を含む文字列を指定します。
下の例では、リンクおよび計画線コード名を入力するよう要求するプロンプトが表示され、それらのコードが追加され、CorridorSurface 定義から削除されます。指定されたコード名が存在しない場合は、System.ArgumentException が投入されます。CorridorSurface 定義にコードが既に存在する場合、例外は投入されません。
string corridorSurfaceName = "Corridor - (1) Top";
string corridorName = "Corridor - (1)";
// get the CorridorSurface by name:
ObjectId corridorId = _civilDoc.CorridorCollection[corridorName];
Corridor corridor = ts.GetObject(corridorId, OpenMode.ForRead) as Corridor;
CorridorSurface corridorSurface = corridor.CorridorSurfaces[corridorSurfaceName];
// get a featureline name and link code:
string linkCodeName = _editor.GetString("Enter a link code: ").StringResult;
string featureLineName = _editor.GetString("Enter a feature line code: ").StringResult;
try
{
corridorSurface.AddLinkCode(linkCodeName, true);
// The new code will be listed here
string[] linkCodes = corridorSurface.LinkCodes();
_editor.WriteMessage("Link codes in corridor surface: \n {0}", String.Join(" \n", linkCodes));
corridorSurface.AddFeatureLineCode(featureLineName);
string[] featureLineCodes = corridorSurface.FeatureLineCodes();
_editor.WriteMessage("Link codes in corridor surface: \n {0}", String.Join(" \n", featureLineCodes));
// remove the new items
corridorSurface.RemoveFeatureLineCode(featureLineName);
corridorSurface.RemoveLinkCode(linkCodeName);
}
// if either code does not exist, this will be thrown:
catch (System.ArgumentException e)
{
_editor.WriteMessage(e.ToString());
}