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?
Revit Parameter Organizer can organize various Revit parameters such as Shared Parameters, Family Parameters, Project Parameters and Built-in Parameter in many good ways.
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 measure, 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 code here to sort it out in some degree.
List<Element> allElements = ElementFinder.FindAllElements(CachedDoc);
Dictionary<StorageType, List<ParameterType>> dictStorageTypeList =
new Dictionary<StorageType, List<ParameterType>>();
foreach (Element e in allElements)
{
foreach (Parameter p in e.Parameters)
{
if (!dictStorageTypeList.ContainsKey(p.StorageType))
{
dictStorageTypeList.Add(p.StorageType, new List<ParameterType>());
}
if (!dictStorageTypeList[p.StorageType].Contains(p.Definition.ParameterType))
{
dictStorageTypeList[p.StorageType].Add(p.Definition.ParameterType);
}
}
}
using (StreamWriter sw = new StreamWriter(@"c:\ParameterTypeToStorageTypeMap.txt"))
{
foreach (KeyValuePair<StorageType, List<ParameterType>> kvp in dictStorageTypeList)
{
sw.WriteLine(kvp.Key);
foreach (ParameterType pt in kvp.Value)
{
sw.WriteLine(string.Format("\t{0}", pt));
}
}
}
The complete code for the ElementFinder.FindAllElements help method is appended below:
public class ElementFinder
{
public static List<Element> FindAllElements(RvtDocument doc)
{
List<Element> list = new List<Element>();
FilteredElementCollector finalCollector = new FilteredElementCollector(doc);
ElementIsElementTypeFilter filter1 = new ElementIsElementTypeFilter (false);
finalCollector.WherePasses(filter1);
ElementIsElementTypeFilter filter2 = new ElementIsElementTypeFilter (true);
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter2));
list = finalCollector.ToList<Element>();
return list;
}
}
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. Another more is that the Text ParameterType can sometimes be of String StorageType but sometimes ElementId! 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 filter parameters based on their StorageType or ParameterType or both plus some other criteria if necessary.
Links to some related articles:
Parameter of Revit API - BuiltInParameter
Parameter Retriever of RevitAddCoder
Parameter of Revit API - Parameter Information
Parameter Infoer of RevitAddCoder
Parameter Typer of RevitAddCoder
Parameter of Revit API - BuiltInParameterGroup
Parameter Grouper of RevitAddCoder
Parameter Filter of RevitAddCoder
Parameter of Revit API - Read/Write Parameter Values
Recent Comments