We talked about adding some extension methods to the BindingMap before. Now let’s see how ProjectParameter BindingMap Extensioner of RevitAddinWizard can assist us to achieve the same goal. The ProjectParameter BindingMap Extensioner can be found either from the Revit Addin Coder sub-menu under the Tools or from the Revit Addin Coder toolbar.
When the menu item or button is clicked, the ProjectParameter BindingMap Extensioner window will show up:
If the OK button is clicked, the following ProjectParameter BindingMap Extensioner will be created and added into the chosen class or the ExtensionCenter:
public static class ExtensionCenter
{
public static bool IsInstance(this Autodesk.Revit.DB.Binding binding)
{
return (binding as InstanceBinding) != null;
}
public static CategorySet GetCategories(this Autodesk.Revit.DB.Binding binding)
{
if (binding.IsInstance())
return (binding as InstanceBinding).Categories;
else
return (binding as TypeBinding).Categories;
}
public static Autodesk.Revit.DB.Definition GetDefiniton(this BindingMap map, string name)
{
DefinitionBindingMapIterator it = map.ForwardIterator();
it.Reset();
while (it.MoveNext())
{
if (it.Key.Name == name)
{
return it.Key;
}
}
return null;
}
public static Autodesk.Revit.DB.Binding GetBinding(this BindingMap map, string name)
{
DefinitionBindingMapIterator it = map.ForwardIterator();
it.Reset();
while (it.MoveNext())
{
if (it.Key.Name == name)
{
return it.Current as Autodesk.Revit.DB.Binding;
}
}
return null;
}
public static KeyValuePair<Autodesk.Revit.DB.Definition, Autodesk.Revit.DB.Binding> GetDefinitonBindingPair(this BindingMap map, string name)
{
DefinitionBindingMapIterator it = map.ForwardIterator();
it.Reset();
while (it.MoveNext())
{
if (it.Key.Name == name)
{
return new KeyValuePair<Definition, Autodesk.Revit.DB.Binding>(it.Key, it.Current as Autodesk.Revit.DB.Binding);
}
}
return new KeyValuePair<Definition,Autodesk.Revit.DB.Binding>(null, null);
}
public static void TruelyClear(this BindingMap map)
{
DefinitionBindingMapIterator it = map.ForwardIterator();
it.Reset();
while (it.MoveNext())
{
map.Remove(it.Key);
}
}
}
In terms of how to use these methods, please refer to previous posts for ideas and code examples.
ProjectParameter BindingMap Extesnioner of RevitAddinWizard can create all these in a second.
Recent Comments