From d209cc9ff456d60c11cf0f8754ef7aea4a649b3f Mon Sep 17 00:00:00 2001 From: Geert Hesselink <54070862+Ghesselink@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:54:20 +0100 Subject: [PATCH] Scale placeangelunit unit type (#4406) * scale placeangleunit * add radian si_conversions * return conversion value of planeangleunit * Update unit.py --- src/ifcopenshell-python/ifcopenshell/util/unit.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 80cbf7d6af..3ea161561d 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -566,7 +566,7 @@ def convert(value, from_prefix, from_unit, to_prefix, to_unit): return value -def calculate_unit_scale(ifc_file): +def calculate_unit_scale(ifc_file, unit_type='LENGTHUNIT'): """Returns a unit scale factor to convert to and from IFC project length units and SI meters Example: @@ -578,6 +578,8 @@ def calculate_unit_scale(ifc_file): :param ifc_file: The IFC file. :type ifc_file: ifcopenshell.file.file + :param unit_type: The type of SI unit, defaults to "LENGTHUNIT" + :type unit_type: str :returns: The scale factor :rtype: float """ @@ -586,12 +588,12 @@ def calculate_unit_scale(ifc_file): units = ifc_file.by_type("IfcUnitAssignment")[0] unit_scale = 1 for unit in units.Units: - if not hasattr(unit, "UnitType") or unit.UnitType != "LENGTHUNIT": + if not hasattr(unit, "UnitType") or unit.UnitType != unit_type: continue while unit.is_a("IfcConversionBasedUnit"): unit_scale *= unit.ConversionFactor.ValueComponent.wrappedValue unit = unit.ConversionFactor.UnitComponent - if unit.is_a("IfcSIUnit"): + if unit.is_a("IfcSIUnit")': unit_scale *= get_prefix_multiplier(unit.Prefix) return unit_scale