アダプティブ コンポーネントは、コンポーネントが多様な固有のコンテキスト条件に柔軟に適応する必要のあるケースを処理できるように設計されています。たとえば、アダプティブ コンポーネントを使用して、ユーザ定義の拘束に適合する複数のコンポーネントを配列複写することにより生成されたシステムを繰り返すことができます。
次のコードは、マス ファミリにアダプティブ コンポーネント ファミリのインスタンスを作成し、インスタンス内のアダプティブ点をマス ファミリ内の点に位置合わせする方法を示します。
|
コード領域: アダプティブ コンポーネント ファミリのインスタンスを作成 |
// find the first placement point that will host the adaptive component
IEnumerable<ReferencePoint> points0 = from obj in new FilteredElementCollector(doc).OfClass(typeof(ReferencePoint)).Cast<ReferencePoint>()
let type = obj as ReferencePoint
where type.Name == "PlacementPoint0" // these names were manually assigned to the points
select obj;
ReferencePoint placementPoint0 = points0.First();
// find the 2nd placement point that will host the adaptive component
IEnumerable<ReferencePoint> points1 = from obj in new FilteredElementCollector(doc).OfClass(typeof(ReferencePoint)).Cast<ReferencePoint>()
let type = obj as ReferencePoint
where type.Name == "PlacementPoint1"
select obj;
ReferencePoint placementPoint1 = points1.First();
if (AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(symbol))
{
// create an instance of the adaptive component
FamilyInstance familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, symbol);
// find the adaptive points in the family instance
IList>ElementId> pointList = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(familyInstance);
ReferencePoint point0 = doc.GetElement(pointList.ElementAt(0)) as ReferencePoint;
ReferencePoint point1 = doc.GetElement(pointList.ElementAt(1)) as ReferencePoint;
// move the adaptive component's points (point0 & point1) to match the position of the placement points
point0.Position = placementPoint0.Position;
point1.Position = placementPoint1.Position;
}
|