Get Parameter Unit in Revit 2021

Get Parameter Unit in Revit 2021

jmyr
Enthusiast Enthusiast
2,888 Views
4 Replies
Message 1 of 5

Get Parameter Unit in Revit 2021

jmyr
Enthusiast
Enthusiast

Hi guys,

 

How do i get the exact unit from specific parameter for example 

Calculated Heating Load = W

Calculated Heating Load per area = W/m²

 

and so on..

jmyr_0-1601891398841.png

 

 

Parameter parameter = SELECTEDZone.get_Parameter(BuiltInParameter.ZONE_CALCULATED_COOLING_LOAD_PARAM);

ForgeTypeId units = parameter.GetUnitTypeId();

0 Likes
Accepted solutions (1)
2,889 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Please read the What's New description on the Forge type id and its use:

 

https://thebuildingcoder.typepad.com/blog/2020/04/whats-new-in-the-revit-2021-api.html#4.1.3

 

Maybe the discussion of Boost your BIM will help:

 

https://thebuildingcoder.typepad.com/blog/2020/07/virtual-au-and-aec-hackathon-units-and-das-job.htm...

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

Thanks for the info. It seems that as of Revit 2021 the below methods have been marked Obsolete.

  • UnitUtils.GetSpecTypeId()
  • UnitUtils.GetUnitType()
  • UnitUtils.GetUnitTypeId()
  • UnitUtils.GetDisplayUnitType()
  • UnitUtils.GetSymbolTypeId()
  • UnitUtils.GetUnitSymbolType()

If I have a Revit Parameter object that contains an area in square meters (25.4 sqM), can you help me identify how I could extract the number (25.4) and the unit type (sqM) from the Parameter? I'm aware I can use Parameter.AsValueString(), but this will give me the concatenated version. I'm trying to get the numbers and the units separately, and it's proving to be a bit tricky.

Thank you in advance.

0 Likes
Message 4 of 5

Dear Charlie,

  

Personally, for simple units such as length and area, I just implement the conversion myself, cf., e.g., The Building Coder samples:

  

https://github.com/jeremytammik/the_building_coder_samples

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/Util.cs#L1206-L...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 5

Thanks @jeremy_tammik 

These are always helpful.

 

My current project requires me to travers all the parameters of various elements from different categories. I can easily get the parameter name, and value.

 

ParameterData paDa = new ParameterData();
paDa.ParameterName = param.Definition.Name;

switch (param.StorageType)
{
     case StorageType.String:
          paDa.ParameterValue = param.AsString(); break;
     case StorageType.Integer:
          paDa.ParameterValue = param.AsInteger().ToString(); break;
     case StorageType.Double:
          paDa.ParameterValue = param.AsDouble().ToString(); break;
     default:
          paDa.ParameterValue = param.AsValueString(); break;
}

My next goal is to get the unit type (mm, cm, cm2, ft, ft2, etc.). Since some of the parameters have complex unit types such as w/m2, I can't predict all the unit types to manually code them in. In order to get the UnitTypeID I'm using 

 

ForgeTypeId unitTypeId = param.GetUnitTypeId();

 

For my application it's important to have the parameter name, parameter value, and parameter unit type as separate fields, so that I may operate / query them individually. The obvious problem is that not every parameter has a Unit Type. So I have to run the line of code above in a try/catch block. Is there a way to identify if the parameter has a Unit Type before trying to execute the line of code above? I have a hunch the application is taking a performance hit since the try / catch block triggers quite often.

 

Thank you.

0 Likes