Converting units of default "Size" parameter in MEP elements

image

Hello, I am currently working on extracting data from several models and am running into issues of inconsistency between authors in regards to how units are displayed for the size of MEP elements. I’m aware that how an element’s size is displayed (for pipes, pipe fittings, conduits, ducts, etc.) is determined by the project unit, but some models within the same project have vastly different settings for Project Units. Some elements display their size in millimeters without the “mm”, some do, and some elements are even displaying their size in imperial units. Although I can extract data from the models, I don’t have the ability to directly modify the project units to achieve what I want. Is there any way to convert the Size parameter of these elements to a more common format?

I am currently accessing the parameter values by using element.LookupParameter(“Size”).AsString()

The AsValueString() method offers the option of including FormatOptions, which accepts both a DisplayUnitType and UnitSymbolType, however the parameter is stored as a String, meaning that AsValueString() returns nothing.

Ideally, I’d like to be able to take both imperial and metric sizes and group them by a common metric. For example, 2" pipe and 50mm pipe (DN) would be grouped together. I could try to do some regular expressions to standardize the format, but this becomes a bit more difficult with fractional inches, especially with elements where the size may have many different measurements (like in a reducing wye, for example).

Any ideas on how to approach this? Any and all help is much appreciated.