適用されたサブアセンブリは、一連の計算されたシェイプ、リンク、およびポイントで構成され、それらはそれぞれ CalculatedShape、CalculatedLink、および CalculatedPoint 型のオブジェクトによって表されます。
foreach (AppliedSubassembly oSubassembly in oASC)
{
ed.WriteMessage("Applied subassembly: Station to baseline: {0}, Offset to baseline: {1}, Elevation to baseline: {2}\n",
oSubassembly.OriginStationOffsetElevationToBaseline.X,
oSubassembly.OriginStationOffsetElevationToBaseline.Y,
oSubassembly.OriginStationOffsetElevationToBaseline.Z);
}
また、適用されたサブアセンブリには、サブアセンブリ データベース内の原型サブアセンブリ(Subassembly 型)のオブジェクト ID も含まれています。
// Get information about the subassembly template:
ObjectId oID = oAppliedSubassembly.SubassemblyId;
Subassembly oSubassembly = ts.GetObject(oID, OpenMode.ForRead) as Subassembly;
ed.WriteMessage("Subassembly name: {0}\n", oSubassembly.Name);
AppliedSubassembly のパラメータには、Parameters プロパティを使用してアクセスすることができます。Parameters コレクションに保持されている項目は、AppliedSubassemblyParam<T> 型で、パラメータの型に応じて異なります。パラメータに読み込みアクセスするには、このコレクションを使用します。パラメータの値を修正するには、GetParameter() メソッドを使用します。これは、パラメータの型に応じて、AppliedSubassemblyParam<T> 型を返します。定義されているパラメータの型は、String、Double、Boolean、Int32 です。Contains() メソッドを使用して、パラメータが存在するかどうかを調べることができます。
この例では、コリドーの最初の BaselineRegion 内の最初の AppliedSubassembly を調べ、定義されているそれぞれのパラメータの型と値を出力します。また、パラメータが存在するかどうかを調べ、パラメータの値を変更します。
string corridorName = "Corridor - (1)";
// get the CorridorSurface by name:
ObjectId corridorId = _civildoc.CorridorCollection[corridorName];
Corridor corridor = ts.GetObject(corridorId, OpenMode.ForRead) as Corridor;
// Get the first applied subassembly in the first assembly in the first BaselineRegion:
BaselineRegion baselineRegion = corridor.Baselines[0].BaselineRegions[0];
AppliedAssembly appliedAssembly = baselineRegion.AppliedAssemblies[0];
AppliedSubassembly appliedSubassembly = appliedAssembly.GetAppliedSubassemblies()[0];
// Get parameter key names:
foreach (IAppliedSubassemblyParam param in appliedSubassembly.Parameters)
{ _editor.WriteMessage("Parameter key name: {0}\n", param.KeyName); }
foreach (var p in appliedSubassembly.Parameters)
{
_editor.WriteMessage("Parameter information: name: {0}, value type: {1}\n", p.KeyName, p.ValueType);
Object vobj = p.ValueAsObject;
if (p.ValueType == typeof(System.String))
{ _editor.WriteMessage("Parameter string value: {0}\n", (String)vobj); }
else if (p.ValueType == typeof(System.Double))
{ _editor.WriteMessage("Parameter double value: {0}\n", (Double)vobj); }
else if (p.ValueType == typeof(System.Int32))
{ _editor.WriteMessage("Parameter int32 value: {0}\n", (Int32)vobj); }
else if (p.ValueType == typeof(system.Boolean))
{ editor.WriteMessage(“Parameter bool value: {0}\n”, (Boolean)vobj);}
// we should never get here:
else { _editor.WriteMessage("Unexpected type.\n"); }
}
// Check whether a parameter exists
Bool result = appliedSubassembly.Contains(“BottomLinkCodes”);
// Change a parameter’s value
AppliedSubassemblyParam<string> param = appliedSubassembly.GetParameter<string>("BottomLinkCodes");
param.Value = "R1S1";