Let’s look at how to use the SharedParameterApplicableRule filter rule in VB.NET to filter out elements which have some project parameter associated with. Supposing we’d like to find all elements which have a specific project parameter, what shall we do?
The following code does so in VB.NET:
Public Shared Function GetWallsHavingProjectParameter(ByVal doc As RvtDocument, ByVal paramName As String) As List(Of IGrouping(Of String, Autodesk.Revit.DB.Element))
Dim rule As New Autodesk.Revit.DB.SharedParameterApplicableRule(paramName)
Dim filter As New Autodesk.Revit.DB.ElementParameterFilter(rule)
Return (New Autodesk.Revit.DB.FilteredElementCollector(doc)).WherePasses(filter).GroupBy(Function(e) e.GetType().Name).ToList()
End Function
A few highlights about the code:
• An ElementParameterFilter needs a filter rule, the SharedParameterApplicableRule in this case.
• The SharedParameterApplicableRule only needs a parameter name.
• The parameter should be a project parameter or bound shared parameter instead of a BuiltInParameter.
• No fast filter like ElementClassFilter is used here as it does not make sense to do so since project parameters can only be bound to some Revit whole categories or element classes rather than to a few particular element instances.
To use the method is very straightforward. Here is some test code in VB.NET:
…
Dim sharedParameterName As String = "PrjParameter1"
Dim list As List(Of IGrouping(Of String, Autodesk.Revit.DB.Element)) = GetWallsHavingProjectParameter(CachedDoc, sharedParameterName)
Dim msg1 As String = String.Format("{0} types of elements have the shared parameter {1}" & vbLf, list.Count, sharedParameterName)
For Each group As IGrouping(Of String, Autodesk.Revit.DB.Element) In list
msg1 += String.Format(vbTab & "Count in type {0}: {1}" & vbLf, group.Key, group.Count())
Next
MessageBox.Show(msg1)
…
So in the test model, four element classes have the project parameter PrjParameter1 associated with and they are WallType, Wall, FamilyInstance, and FamilySymbol. The element count in each class type is also reported.
ElementParameterFilter Creator of RevitAddinCoder can create the code automatically in no time.
Recent Comments