アダプティブ コンポーネント

アダプティブ コンポーネントは、コンポーネントが多様な固有のコンテキスト条件に柔軟に適応する必要のあるケースを処理できるように設計されています。たとえば、アダプティブ コンポーネントを使用して、ユーザ設定の拘束に適合する複数のコンポーネントを配列することにより生成されたシステムを繰り返すことができます。

次のコードは、マス ファミリにアダプティブ コンポーネント ファミリのインスタンスを作成して、それぞれのポイントの位置を数学的に設定する方法を示します。

コード領域: アダプティブ コンポーネント ファミリのインスタンスを作成

private void CreateAdaptiveComponentInstance(Document document, FamilySymbol symbol)
{
    // Create a new instance of an adaptive component family
    FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(document, symbol);

    // Get the placement points of this instance
    IList<ElementId> placePointIds = new List<ElementId>();
    placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance);
    double x = 0;

    // Set the position of each placement point
    foreach (ElementId id in placePointIds)
    {
        ReferencePoint point = document.GetElement(id) as ReferencePoint;
        point.Position = new Autodesk.Revit.DB.XYZ(10*x, 10*Math.Cos(x), 0);
        x += Math.PI/6;
    }
}

アダプティブ コンポーネントを一括作成するには、FamilyInstanceCreationData コンストラクタのオーバーロードを使用します。このコンストラクタは FamilySymbol とアダプティブ インスタンスが初期化される XYZ アダプティブ ポイントのリストの 2 つのパラメータを使用します。FamilyInstanceCreationData オブジェクトのリストを使用する Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstances2()メソッドと連携することで、複数のアダプティブ コンポーネントを一度に追加できます。個々のアダプティブ コンポーネントを 1 つずつ配置するよりもこの方法を使用した方が効率的な場合もあります。