Revit .NET API Element class provides quite some different methods/properties to get parameter(s) from its instance. Here they are:
LookupParameter(String)
GetParameters(String)
get_Parameter(Guid)
get_Parameter(BuiltInParameter)
get_Parameter(Definition)
The last three are indexed properties actually and can be used to retrieve the exact parameter of concern, shared, built-in or any with a certain definition (internal or external). Since Guid, BuiltInParameter and Definition are unique, the found parameter is single and good.
However, the LookupParameter() and GetParameters() methods are kindly confusing, especially the lookup one, which returns only the first found parameter with the given name even if multiple exist, or nothing for none. Also, they are language dependent, i.e. if the parameter name is hard coded in English such as 'Length', the tool will not work in German or French Revit, needless to say, some other different languages such as Japaneses, Korean and Chinese.
So the best practice is to get the name input from users rather than hard code it! Even if so, the LookupParameter() one may right ignore the real concern in case of multiple parameters (shared, built-in, and custom) with the same name but just yield something unexpected. Not sure why it came out anyway. Maybe Revit did not allow different parameters have the same name within an Element instance?! Even if the API itself knows the fact and mentions here and there in its help file and people talk about it all over anyway, it has been staying there for almost the whole Revit API life so far, but many other namespaces, classes, methods, and properties have been deprecated or even removed!!
The GetParameters() method behave well enough, if more than one parameters, we can double check with users through a list box. So, please forget about LookupParameter() but use GetParameters() if really necessary.
Recent Comments