Parameter and Category are two most important objects in the Revit API and they are related to each other. There are hundreds of BuiltInParameter enumerator values and many times we need to narrow down them to some sub sets based on some criteria, for example, one or a few categories. We are going to take about these in this article.
The help class ParameterFilterUtilities in the Revit API can help us achieve the goal, and the key method is GetFilterableParametersInCommon().
Supposing we’d like to find all applicable parameters both built-in and custom to the wall category, what shall we do?
The following VB.NET code does so:
Public Shared Function GetApplicableParametersOfWalls(ByVal doc As RvtDocument) As Object()
Dim catList As New List(Of Autodesk.Revit.DB.ElementId)()
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_Walls).Id)
Dim paramList As List(Of Autodesk.Revit.DB.ElementId) = Autodesk.Revit.DB.ParameterFilterUtilities.GetFilterableParametersInCommon(doc, catList).ToList()
Dim list1 As New List(Of BuiltInParameter)()
Dim list2 As New List(Of String)()
For Each id As Autodesk.Revit.DB.ElementId In paramList
If id.IntegerValue < 0 Then
list1.Add(DirectCast(id.IntegerValue, BuiltInParameter))
Else
list2.Add(doc.Element(id).Name)
End If
Next
Return New Object() {list1, list2}
End Function
The following test code writes the information to a CSV file:
…
Dim appParams1 As Object() = GetApplicableParametersOfWalls(CachedDoc)
Using sw As New StreamWriter("c:\temp\AppParamsOfWalls.csv")
Dim list1 As List(Of BuiltInParameter) = TryCast(appParams1(0), List(Of BuiltInParameter))
Dim list2 As List(Of String) = TryCast(appParams1(1), List(Of String))
For Each p As BuiltInParameter In list1
sw.WriteLine(p.ToString())
Next
sw.WriteLine()
For Each s As String In list2
sw.WriteLine(s)
Next
End Using
…
Here is the content of the CSV file:
KEYNOTE_PARAM
REIN_EST_BAR_VOLUME
HOST_VOLUME_COMPUTED
HOST_AREA_COMPUTED
ALL_MODEL_MODEL
ALL_MODEL_MANUFACTURER
ALL_MODEL_INSTANCE_COMMENTS
ALL_MODEL_TYPE_COMMENTS
ALL_MODEL_URL
ALL_MODEL_DESCRIPTION
CURVE_ELEM_LENGTH
UNIFORMAT_DESCRIPTION
UNIFORMAT_CODE
SYMBOL_FAMILY_NAME_PARAM
ALL_MODEL_TYPE_NAME
WINDOW_TYPE_ID
DOOR_FIRE_RATING
DOOR_COST
ALL_MODEL_MARK
WALL_STRUCTURAL_USAGE_PARAM
FUNCTION_PARAM
WALL_ATTR_WIDTH_PARAM
ExistingParameter1
NewParameter1
TemporarySharedParameter
Volume41
Volume42
PrjParameter
Let us have a look at another example, finding all applicable parameters both built-in and custom to the window and door category, what shall we do?
The following VB.NET code does so:
Public Shared Function GetApplicableParametersOfWindowsDoors(ByVal doc As RvtDocument) As Object()
Dim catList As New List(Of Autodesk.Revit.DB.ElementId)()
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_Windows).Id)
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_Doors).Id)
Dim paramList As List(Of Autodesk.Revit.DB.ElementId) = Autodesk.Revit.DB.ParameterFilterUtilities.GetFilterableParametersInCommon(doc, catList).ToList()
Dim list1 As New List(Of BuiltInParameter)()
Dim list2 As New List(Of String)()
For Each id As Autodesk.Revit.DB.ElementId In paramList
If id.IntegerValue < 0 Then
list1.Add(DirectCast(id.IntegerValue, BuiltInParameter))
Else
list2.Add(doc.Element(id).Name)
End If
Next
Return New Object() {list1, list2}
End Function
Again, the following test code writes the information to a CSV file:
…
Dim appParams2 As Object() = GetApplicableParametersOfWindowsDoors(CachedDoc)
Using sw As New StreamWriter("c:\temp\AppParamsOfWindowsDoors.csv")
Dim list1 As List(Of BuiltInParameter) = TryCast(appParams1(0), List(Of BuiltInParameter))
Dim list2 As List(Of String) = TryCast(appParams1(1), List(Of String))
For Each p As BuiltInParameter In list1
sw.WriteLine(p.ToString())
Next
sw.WriteLine()
For Each s As String In list2
sw.WriteLine(s)
Next
End Using
…
Here is the output:
KEYNOTE_PARAM
ALL_MODEL_MODEL
ALL_MODEL_MANUFACTURER
ALL_MODEL_INSTANCE_COMMENTS
ALL_MODEL_TYPE_COMMENTS
ALL_MODEL_URL
ALL_MODEL_DESCRIPTION
OMNICLASS_DESCRIPTION
OMNICLASS_CODE
UNIFORMAT_DESCRIPTION
UNIFORMAT_CODE
SCHEDULE_LEVEL_PARAM
SYMBOL_FAMILY_NAME_PARAM
ALL_MODEL_TYPE_NAME
WINDOW_TYPE_ID
INSTANCE_HEAD_HEIGHT_PARAM
INSTANCE_SILL_HEIGHT_PARAM
FAMILY_ROUGH_WIDTH_PARAM
FAMILY_ROUGH_HEIGHT_PARAM
GENERIC_WIDTH
DOOR_HEIGHT
DOOR_OPERATION_TYPE
GENERIC_CONSTRUCTION_TYPE
DOOR_COST
ALL_MODEL_MARK
Parameter Categorizer of RevitAddinWizard can create the code automatically in no time.
Recent Comments