In previous blog, we said that user can retrieve one parameter from an element through Element.get_Parameter(…) function.
Revit API also provides properties for API developer to get all parameters of an element, the two properties are:
Element.Parameters
Element.ParametersMap
Both properties contain all public parameters the element has, however, they also differ a little and we should use them in different ways.
The first property Parameters returns a set of Parameter, we can use this if we want to iterate all public parameters. The code would like:
ParameterSetIterator it = Element.Parameters.ForwardIterator();
while (it.MoveNext())
{
Parameter param = it.Current as Parameter;
// Maybe check some conditiones like param.Definition, StorageType etc.
// do something for param…
}
The second property ParametersMap returns a map of Parameters, whose key is the name of the parameter. So if we want to retrieve several parameters from element through their name, use this property would be better (get_Parameter can also achieve this, however, that function will iterate all parameters each time it calls). The code looks like:
ParameterMap paramMap = eRef.Element.ParametersMap;
if (paramMap.Contains(“ParamA”))
{
Parameter param = paramMap.get_Item(“ParamA”);
// do something for param …
}
if (paramMap.Contains(“ParamB”))
{
Parameter param = paramMap.get_Item(“ParamB”);
// do something for param …
}
if (paramMap.Contains(“ParamC”))
{
Parameter param = paramMap.get_Item(“ParamC”);
// do something for param …
}
Attention: Check whether the map contains the parameter before get it, otherwise, it will throw an exception if the name is not found.
Comments
Leave a comment