Over a year ago, I mentioned the LabelUtils class introduced in the Revit 2011 API. Here is another question that came up and shows that it might be useful to point it out again:
Question: I need access to the definition of an internal (built-in) parameter, because I want to retrieve its name via Autodesk.Revit.DB.Definition.Name. I know there's an overload of the Element.Parameter property which takes a BuiltInParameter argument. The problem is that there is no element available at the time when I need to obtain the parameter name. So I am looking for something similar to Document.Settings.Categories which allows global access to built-in categories. I've tried to find something similar via Document.ParameterBindings, but this map seems to contain only external definitions, i.e. definitions of shared parameters, not of built-in ones.
Answer: Is this what you are after?
string s = string.Empty; foreach( BuiltInParameter bip in Enum.GetValues( typeof( BuiltInParameter ) ) ) { s += "\r\n" + bip.ToString(); } TaskDialog.Show( "Parameter Names", s );
It retrieves the string values of all the built-in parameter enumeration values.
Reponse: No, I do not want to use the BuiltInParameter.ToString method, since the string is presented to the user. Therefore, I would like to use the Parameter.Definition.Name instead, which is user friendlier and also localized.
To access the definition name, I would need to have an element with all the parameters I am interested in attached to it. If I had such an element 'e', I could use the following code to create a mapping from built-in parameters to the corresponding user visible names:
Element e; Dictionary<BuiltInParameter, string> mapBipToName = new Dictionary<BuiltInParameter, string>(); foreach( BuiltInParameter bip in Enum.GetValues( typeof( BuiltInParameter ) ) ) { // translate built-in enum to parameter name Parameter p = e.get_Parameter( bip ); if( null != p ) { mapBipToName.Add( bip, p.Definition.Name ); } }
However, I do not have such an element available.
Answer: Please have a look at the LabelUtils class, especially its GetLabelFor method taking a BuiltInParameter argument.
It returns the user-visible name for a given built-in parameter. The name is obtained in the current Revit language.
Reponse: Exactly what I was looking for! Thank you.
Jeremy, your blog is awesome. I had exactly the same question as this poster and your answer of “GetLabelFor” was spot on what I needed. Thank you very much for producing such a wonderful Revit API resource.
Posted by: Phillip Miller | June 26, 2012 at 18:05
Dear Phillip,
Wow, thank you very much for your appreciation!
I am glad it hit the nail on the head :-)
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 28, 2012 at 03:38
Dear Jeremy,
I would like to have the geometry data of component elements such as width, thickness, height of windows, doors, and other furniture. I've tried with Built-in Parameters such as WINDOW_WIDTH (for windows elements) or other parameters related to Width of Element.Parameters, but unfortunately the results returned from method AsValueString() always "0.0" Could you tell me how I could do to retrieve this kind of data.
Schönes Wochenende.
Viele Grüße,
Trang
Posted by: Trang | July 28, 2012 at 06:11
Dear Trang,
Accessing this data via family parameters depends on the family definition, which is freely defined by the user, so there are no fixed rules.
You have to explore each family definition whose data you wish to access and adapt to that.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 16, 2012 at 09:06
Some parameters have values get from other enumerations, for example: "Condition Type" parameter gets values from ConditionType enumerated type. Is the possibility to get
correspondence between property and enumerated type for its values?
Is it possible to make easily than this code?
private int selectEnumValue(string paramName, string paramValue)
{
int intValue = -1;
Type paramEnum;
switch (paramName)
{
case "Condition Type":
paramEnum = typeof(ConditionType);
break;
case "Return Airflow":
paramEnum = typeof(ReturnAirflowType);
break;
case "Space Type":
paramEnum = typeof(SpaceType);
if (!(paramValue.Replace(" ", "").Equals("NoSpaceType", StringComparison.OrdinalIgnoreCase) ||
paramValue.Replace(" ", "").Equals("", StringComparison.OrdinalIgnoreCase)))
paramValue = "k" + paramValue;
break;
default:
paramEnum = null;
break;
}
if (paramEnum != null)
{
string[] enumNames = paramEnum.GetEnumNames();
for (int i = 0; i < enumNames.Length; i++)
{
if (enumNames[i].Equals(paramValue.Replace(" ", "").Replace("-", "").Replace(@"/", "Or"), StringComparison.OrdinalIgnoreCase))
{
intValue = i;
break;
}
}
}
return intValue;
}
Posted by: Anatoly | July 29, 2013 at 16:39
Dear Anatoly,
Thank you for your interesting question and suggestion.
Sorry I took so long to respond, I have a large backlog of cases and comments and stuff.
The only thing I can think of to simplify and simultaneously complexify it would be to apply pattern matching between the parameter name and the enumeration names.
For instance, you could split the parameter name on white space and search for an enumeration name that contains all of the fragments.
That would be a pretty reliable way to ensure they match, wouldn't it?
And fun and elegant too, I think.
That might even be worth a blog post on its own, I think.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 30, 2013 at 08:00
Hi I want to change the built in parameter worksetID, to the workset ID of another element, how can i do this?
Posted by: frank halliday | September 23, 2013 at 06:55
Dear Frank,
http://thebuildingcoder.typepad.com/blog/2013/01/change-element-workset.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | September 27, 2013 at 03:43
Hi,Jeremy,your blog is amazing! On revit 2013, I got an error "Cannot find the BuiltInParameter STAIRS_LANDINGTYPE_TREADRISER_TYPE."when " foreach (BuiltInParameter bip in Enum.GetValues(typeof(BuiltInParameter))){strDetail = Autodesk. Revit.DB.LabelUtils.GetLabelFor(bip);}",Is there something changed with API2013?
BTW, you and Joe Ye really did a good job for our beginners, thank you so much!
Howie
Posted by: Howie | December 03, 2013 at 08:01
Dear Howie,
Thank you for your appreciation. I'll pass it on to Joe as well. I am very glad to hear you find it useful.
Yes, the whole stair implementation was substantially updated in Revit 2013:
http://thebuildingcoder.typepad.com/blog/2013/03/whats-new-in-the-revit-2013-api.html
Search for 'Major Enhancements to the Revit API' and 'Stairs and railings API'.
Cheers, Jeremy.
Posted by: Jeremy Tammik | December 05, 2013 at 20:44