mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Convert units to project settings when guessing quantities
This commit is contained in:
@@ -62,3 +62,37 @@ def get_unit_name(text):
|
||||
for name in unit_names:
|
||||
if name in text.upper().replace('METER', 'METRE'):
|
||||
return name
|
||||
|
||||
def convert(value, from_prefix, from_unit, to_prefix, to_unit):
|
||||
"""Converts between length, area, and volume units
|
||||
|
||||
:param value: The numeric value you want to convert
|
||||
:type value: float
|
||||
:param from_prefix: A prefix from IfcSIPrefix. Can be None.
|
||||
:type from_prefix: string
|
||||
:param from_unit: IfcSIUnitName or IfcConversionBasedUnit.Name
|
||||
:type from_unit: string
|
||||
:param to_prefix: A prefix from IfcSIPrefix. Can be None.
|
||||
:type to_prefix: string
|
||||
:param to_unit: IfcSIUnitName or IfcConversionBasedUnit.Name
|
||||
:type to_unit: string
|
||||
"""
|
||||
if from_unit in si_conversions:
|
||||
value *= si_conversions[from_unit]
|
||||
elif from_prefix:
|
||||
value *= get_prefix_multiplier(from_prefix)
|
||||
if 'SQUARE' in from_unit:
|
||||
value *= get_prefix_multiplier(from_prefix)
|
||||
elif 'CUBIC' in from_unit:
|
||||
value *= get_prefix_multiplier(from_prefix)
|
||||
value *= get_prefix_multiplier(from_prefix)
|
||||
if to_unit in si_conversions:
|
||||
return value * (1 / si_conversions[to_unit])
|
||||
elif to_prefix:
|
||||
value *= (1 / get_prefix_multiplier(to_prefix))
|
||||
if 'SQUARE' in from_unit:
|
||||
value *= (1 / get_prefix_multiplier(to_prefix))
|
||||
elif 'CUBIC' in from_unit:
|
||||
value *= (1 / get_prefix_multiplier(to_prefix))
|
||||
value *= (1 / get_prefix_multiplier(to_prefix))
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user