The Revit API provides two ways to categorize Parameter instances regarding data types, ParameterType and StorageType. The StorageType enumeration only has five values:
None
Integer
Double
String
ElementId
This type seems to be specifically for programmers. The None is apparently to indicate that the associated Parameter does not really have a meaningful data type. The Integer, Double and String are clear and easy for programmers to understand since every programming language has these data types. The ElementId is very Revit API particular but it is not something hard to understand as it’s widely used in the API and almost everything needs the id to identify itself in a Revit session.
The ParameterType is much more complex, has a lot more values, and is hard to understand sometimes. Only a handful is appended here for reference:
Invalid
Integer
Number
Length
Area
Volume
Angle
URL
Material
YesNo
Force
…
It provides a value, Invalid, which looks similar to the None in the StorageType, to indicate some Parameter does not really carry any meaningful ParameterType information. What are other values about then and do they always have a corresponding StorageType value?
The answer to the latter is apparently YES as each Parameter has both a StorageType and a ParameterType. As far as the first question is concerned, the enumeration value itself is pretty explanatory, e.g. Length representing some linear measurement, YesNo meaning a Boolean value, Material indicating a material reference, etc. In addition, obviously, each StorageType value can map to multiple ParameterType values, but it is not obvious in the API or the Revit itself which StorageType value maps exactly to what ParameterType values.
Let’s work out some VB.NET code here to sort it out in some degree.
Dim allElements As List(Of Autodesk.Revit.DB.Element) = ElementFinder.FindAllElements(CachedDoc)
Dim dictStorageTypeList As New Dictionary(Of StorageType, List(Of ParameterType))()
For Each e As Autodesk.Revit.DB.Element In allElements
For Each p As Parameter In e.Parameters
If Not dictStorageTypeList.ContainsKey(p.StorageType) Then
dictStorageTypeList.Add(p.StorageType, New List(Of ParameterType)())
End If
If Not dictStorageTypeList(p.StorageType).Contains(p.Definition.ParameterType) Then
dictStorageTypeList(p.StorageType).Add(p.Definition.ParameterType)
End If
Next
Next
Using sw As New StreamWriter("c:\ParameterTypeToStorageTypeMap.txt")
For Each kvp As KeyValuePair(Of StorageType, List(Of ParameterType)) In dictStorageTypeList
sw.WriteLine(kvp.Key)
For Each pt As ParameterType In kvp.Value
sw.WriteLine(String.Format(vbTab & "{0}", pt))
Next
Next
End Using
The complete code for the ElementFinder.FindAllElements help method is appended below:
Public Class ElementFinder
Public Shared Function FindAllElements(ByVal doc As RvtDocument) As List(Of Autodesk.Revit.DB.Element)
Dim list As New List(Of Autodesk.Revit.DB.Element)()
Dim finalCollector As New Autodesk.Revit.DB.FilteredElementCollector(doc)
Dim filter1 As New Autodesk.Revit.DB.ElementIsElementTypeFilter(False)
finalCollector.WherePasses(filter1)
Dim filter2 As New Autodesk.Revit.DB.ElementIsElementTypeFilter(True)
finalCollector.UnionWith((New Autodesk.Revit.DB.FilteredElementCollector(doc)).WherePasses(filter2))
list = finalCollector.ToElements()
Return list
End Function
End Class
By the way, it was created in a second by Element Finder of RevitAddinWizard.
The content of the file ParameterTypeToStorageTypeMap.txt may look like the following depending on what model the code will be tried on (bigger models with more parameters and more varieties will yield more comprehensive results):
Integer
Invalid
YesNo
Integer
Double
Number
105
Length
Currency
Angle
ElectricalPotential
TemperalExp
Stress
UnitWeight
Area
Volume
Slope
106
PipingRoughness
HVACAreaDividedByHeatingLoad
HVACCoolingLoadDividedByArea
HVACCoolingLoad
HVACHeatingLoadDividedByArea
HVACAirflow
HVACAirflowDensity
HVACHeatingLoad
HVACAreaDividedByCoolingLoad
HVACFactor
ElectricalPowerDensity
HVACHeatGain
HVACTemperature
ElementId
Invalid
Text
Material
FamilyType
None
Invalid
String
Text
URL
Invalid
One odd thing as can be noticed is that a Parameter can have a good StorageType such as ElementId and String but a bad ParameterType (Invalid) at the same time. And keen readers may have noticed those 105 and 106 stuffs and wondered what they are really about. Frankly, I have been wondering too!
Parameter Filter of RevitAddinWizard can create parameter type filters in C# or VB.NET based on their StorageType or ParameterType or both plus some other criteria if necessary.
Recent Comments