diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index a9b6e31c34..35f97ae3cd 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -566,8 +566,8 @@ def convert(value, from_prefix, from_unit, to_prefix, to_unit): return value -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 +def calculate_unit_scale(ifc_file, unit_type="LENGTHUNIT"): + """Returns a unit scale factor to convert to and from IFC project units and SI units. Example: diff --git a/src/ifcopenshell-python/test/util/test_unit.py b/src/ifcopenshell-python/test/util/test_unit.py index 4b978a6e82..52a6a93178 100644 --- a/src/ifcopenshell-python/test/util/test_unit.py +++ b/src/ifcopenshell-python/test/util/test_unit.py @@ -20,6 +20,7 @@ import pytest import test.bootstrap import ifcopenshell.api import ifcopenshell.util.unit as subject +from math import pi class TestCalculateUnitScale(test.bootstrap.IFC4): @@ -30,6 +31,11 @@ class TestCalculateUnitScale(test.bootstrap.IFC4): ifcopenshell.api.run("unit.assign_unit", self.file, units=[length]) assert subject.calculate_unit_scale(self.file) == 0.3048 * 0.001 + angle = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="degree") + angle.ConversionFactor.UnitComponent.Prefix = "MILLI" + ifcopenshell.api.run("unit.assign_unit", self.file, units=[angle]) + assert subject.calculate_unit_scale(self.file, "PLANEANGLEUNIT") == pi / 180 * 0.001 + class TestFormatLength(test.bootstrap.IFC4): def test_run(self):