バインドは、共有パラメータをモデル内の特定のカテゴリの要素に関連付けるものです。利用可能なバインドには、インスタンス バインドとタイプ バインドの 2 つがあります。この 2 つのバインドの主な相違点は、インスタンスでバインドするパラメータは、そのカテゴリの要素のすべてのインスタンスに表示される点です。あるパラメータを変更しても、パラメータのその他のインスタンスには影響しません。タイプでバインドするパラメータはタイプ オブジェクトにのみ表示され、そのタイプを使用するすべてのインスタンスが共有します。タイプでバインドするパラメータを変更すると、そのタイプを使用する要素のすべてのインスタンスが影響を受けます。注記: 定義はインスタンスとタイプのいずれかにバインドできますが、両方にバインドすることはできません。
パラメータをバインドするには:
Autodesk.Revit.DB 名前空間内の次のクラスとメソッドでは、要素へのパラメータのバインドに関する詳細情報を得られます。
TypeBinding オブジェクトは、プロパティを壁タイプなどの Revit タイプにバインドするのに使用されます。これは、同一のタイプ バインド内のすべてのインスタンスでプロパティが共有されるという点で、インスタンス バインドとは異なります。あるタイプのパラメータを変更すると、同じタイプのすべてのインスタンスに影響します。
次のコード サンプルは、共有パラメータ ファイルを使用したパラメータ定義の追加方法を示しています。次のコードは、Revit UI の図でダイアログ ボックスを使用したときと同じアクションを実行します。パラメータ定義は次の順序で作成されます。
コード領域 22-7: 共有パラメータ ファイルを使用して、タイプ パラメータ定義を追加 |
public bool SetNewParameterToTypeWall(UIApplication app, DefinitionFile myDefinitionFile) { // Create a new group in the shared parameters file DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("MyParameters"); // Create a type definition ExternalDefinitonCreationOptions option = new ExternalDefinitonCreationOptions("CompanyName", ParameterType.Text); Definition myDefinition_CompanyName = myGroup.Definitions.Create(option); // Create a category set and insert category of wall to it CategorySet myCategories = app.Application.Create.NewCategorySet(); // Use BuiltInCategory to get category of wall Category myCategory = app.ActiveUIDocument.Document.Settings.Categories.get_Item( BuiltInCategory.OST_Walls); myCategories.Insert(myCategory); //Create an object of TypeBinding according to the Categories TypeBinding typeBinding = app.Application.Create.NewTypeBinding(myCategories); // Get the BingdingMap of current document. BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; // Bind the definitions to the document bool typeBindOK = bindingMap.Insert(myDefinition_CompanyName, typeBinding, BuiltInParameterGroup.PG_TEXT); return typeBindOK; } |
InstanceBinding オブジェクト インスタンスは、パラメータ定義と特定のカテゴリ インスタンス間のバインドを表します。
バインドすると、インスタンスのすべてのプロパティ ダイアログボックスにパラメータが表示されます(表示プロパティが true に設定されている場合)。任意のインスタンスでパラメータを変更しても、他のインスタンスの値は変更されません。
次のコード サンプルは、共有パラメータ ファイルを使用したパラメータ定義の追加方法を示しています。パラメータ定義は次の順序で追加されます。
壁カテゴリに基づいて、現在のドキュメント内の各壁インスタンス パラメータに定義がバインドされます。
コード領域 22-8: 共有パラメータ ファイルを使用して、インスタンス パラメータ定義を追加 |
public bool SetNewParameterToInstanceWall(UIApplication app, DefinitionFile myDefinitionFile) { // create a new group in the shared parameters file DefinitionGroups myGroups = myDefinitionFile.Groups; DefinitionGroup myGroup = myGroups.Create("MyParameters1"); // create an instance definition in definition group MyParameters ExternalDefinitonCreationOptions option = new ExternalDefinitonCreationOptions("Instance_ProductDate", ParameterType.Text); // Don't let the user modify the value, only the API option.UserModifiable = false; // Set tooltip option.Description = "Wall product date"; Definition myDefinition_ProductDate = myGroup.Definitions.Create(option); // create a category set and insert category of wall to it CategorySet myCategories = app.Application.Create.NewCategorySet(); // use BuiltInCategory to get category of wall Category myCategory = app.ActiveUIDocument.Document.Settings.Categories.get_Item( BuiltInCategory.OST_Walls); myCategories.Insert(myCategory); //Create an instance of InstanceBinding InstanceBinding instanceBinding = app.Application.Create.NewInstanceBinding(myCategories); // Get the BingdingMap of current document. BindingMap bindingMap = app.ActiveUIDocument.Document.ParameterBindings; // Bind the definitions to the document bool instanceBindOK = bindingMap.Insert(myDefinition_ProductDate, instanceBinding, BuiltInParameterGroup.PG_TEXT); return instanceBindOK; } |