Hi everyone, I am moving my first steps in pyRevit. I am using a metric template within my file. I am getting flow value from the ducts selected in Revit using this script:
for el in selection:
if el.LookupParameter(‘Flow’):
print(el.LookupParameter(‘Flow’).AsDouble())
The values I obtain are different from the ones I can read in the properties palette, which are displayed in m^3/h. I tryed to solve the problem by using variables to convert the values directly inside pyRevit, but it is tricky because I have to pay attention every time I deal with numeric values. Another way I tryed is to obtain value .AsValueString(), and but I don’t think this is the best method, because in this case I obtain strings that report also the unit of measure. My question is: is there a way to use directly the same unit of measure automatically, to avoid undesired issues in my calculations?
Thank you in advice for your attention
Thank you for your fast reply. Can I please ask how do you “clean” your string after you obtain it? I tryed list slicing, but I don’t think It is a good method because it depends on the number of charatcters I have to remove , that can be different every time I deal with different kind of parameters.
@Jean-Marc , do you have an excerpt of a script that shows how the “AsValueString” should be used?
I am trying to get an elevation of a level AsValueString but I keep getting errors.
Thank you!
This isn’t a ‘smart’ fix but it’s worked for me in similar situations… Units default to imperial when using python (API or Dynamo python nodes) so I just convert the units to sqm by multiplying the double by the conversion factor. For example to get the sqm value:
area = el.LookupParameter(‘Flow’).AsDouble()
area = area * 10.76391041671