Keen readers may have noticed that in the previous post some code methods are not really in the BindingMap class. Sorry for that. They are some extensions to the BindingMap class.
Here they are. Some more not used yet have also been appended:
<System.Runtime.CompilerServices.Extension()> _
Public Function IsInstance(ByVal binding As Autodesk.Revit.DB.Binding) As Boolean
Return TryCast(binding, InstanceBinding) IsNot Nothing
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function GetCategories(ByVal binding As Autodesk.Revit.DB.Binding) As CategorySet
If binding.IsInstance() Then
Return TryCast(binding, InstanceBinding).Categories
Else
Return TryCast(binding, TypeBinding).Categories
End If
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function GetDefiniton(ByVal map As BindingMap, ByVal name As String) As Autodesk.Revit.DB.Definition
Dim it As DefinitionBindingMapIterator = map.ForwardIterator()
it.Reset()
While it.MoveNext()
If it.Key.Name = name Then
Return it.Key
End If
End While
Return Nothing
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function GetBinding(ByVal map As BindingMap, ByVal name As String) As Autodesk.Revit.DB.Binding
Dim it As DefinitionBindingMapIterator = map.ForwardIterator()
it.Reset()
While it.MoveNext()
If it.Key.Name = name Then
Return TryCast(it.Current, Autodesk.Revit.DB.Binding)
End If
End While
Return Nothing
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function GetDefinitonBindingPair(ByVal map As BindingMap, ByVal name As String) As KeyValuePair(Of Autodesk.Revit.DB.Definition, Autodesk.Revit.DB.Binding)
Dim it As DefinitionBindingMapIterator = map.ForwardIterator()
it.Reset()
While it.MoveNext()
If it.Key.Name = name Then
Return New KeyValuePair(Of Definition, Autodesk.Revit.DB.Binding)(it.Key, TryCast(it.Current, Autodesk.Revit.DB.Binding))
End If
End While
Return New KeyValuePair(Of Definition, Autodesk.Revit.DB.Binding)(Nothing, Nothing)
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Sub TruelyClear(ByVal map As BindingMap)
Dim it As DefinitionBindingMapIterator = map.ForwardIterator()
it.Reset()
While it.MoveNext()
map.Remove(it.Key)
End While
End Sub
Just a kind reminder in case: please put these extension methods into a VB.NET module instead of a class and import its namespace into the source that you’d like to use them. Enjoy!
ProjectParameter Extensioner of RevitAddinCoder will create them in either VB.NET or C# automatically (depending on the current project language) into where we want them to be in no time.
Recent Comments