Binding. Autodesk 2014 Platform API
Реклама
Реклама
Binding
In the add-in code, complete the following steps to bind a specific parameter:
1. Use an InstanceBinding or a TypeBinding object to create a new Binding object that includes the categories to which the parameter is bound.
2. Add the binding and definition to the document using the Document.ParameterBindings object.
The following list provides more information about the classes and methods in the previous diagram.
•
Autodesk.Revit.Parameters.BindingMap Class - The BindingMap object is retrieved from the Document.ParameterBindings property. o
Parameter binding connects a parameter definition to elements within one or more categories. o
The map is used to interrogate existing bindings as well as generate new parameter bindings using the Insert method.
• Parameters.BindingMap.Insert (Definition, Binding) Method - The binding object type dictates whether the parameter is bound to all instances or just types. o
A parameter definition cannot be bound to both instances and types. o
If the parameter binding exists, the method returns false.
Type Binding
The Autodesk.Revit.Parameters.TypeBinding objects are used to bind a property to a Revit type, such as a wall type. It differs from Instance bindings in that the property is shared by all instances identified in type binding. Changing the parameter for one type affects all instances of the same type.
Figure 132: Parameter Properties dialog box Type Binding
The following code segment demonstrates how to add parameter definitions using a shared parameter file. The following code performs the same actions as using the dialog box in the previous picture. Parameter definitions are created in the following order:
1. A shared parameter file is created.
2. A definition group and a parameter definition are created for the Walls type.
3. The definition is bound to the wall type parameter in the current document based on the wall category.
Code Region 22-7: Adding type parameter definitions using a shared parameter file
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
Definition myDefinition_CompanyName =
myGroup.Definitions.Create("CompanyName", ParameterType.Text);
// 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;
BuiltInParameterGroup.PG_TEXT); return typeBindOK;
}
// Bind the definitions to the document bool typeBindOK = bindingMap.Insert(myDefinition_CompanyName, typeBinding,
Instance Binding
The Autodesk.Revit.Parameters.InstanceBinding object indicates binding between a parameter definition and a parameter in certain category instances. The following diagram illustrates Instance Binding in the Walls category.
Once bound, the parameter appears in all property dialog boxes for the instance. Changing the parameter in any one instance does not change the value in any other instance.
Figure 133: Parameter Properties dialog box Instance Binding
Изтегляне
Реклама