mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
util/unit.py::calculate_unit_scale() Check for valid unit_type
This commit is contained in:
@@ -691,6 +691,14 @@ def calculate_unit_scale(ifc_file: ifcopenshell.file, unit_type: str = "LENGTHUN
|
|||||||
:param unit_type: The type of SI unit, defaults to "LENGTHUNIT"
|
:param unit_type: The type of SI unit, defaults to "LENGTHUNIT"
|
||||||
:returns: The scale factor
|
:returns: The scale factor
|
||||||
"""
|
"""
|
||||||
|
if (
|
||||||
|
unit_type
|
||||||
|
not in ifcopenshell.ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
|
||||||
|
.declaration_by_name("IfcUnitEnum")
|
||||||
|
.enumeration_items()
|
||||||
|
):
|
||||||
|
raise ValueError(f"Unit type {unit_type!r} does not name a valid type")
|
||||||
|
|
||||||
# Currently we assume that all ifc projects must have IfcProject.
|
# Currently we assume that all ifc projects must have IfcProject.
|
||||||
if not (projects := ifc_file.by_type("IfcProject")) or not (units := projects[0].UnitsInContext):
|
if not (projects := ifc_file.by_type("IfcProject")) or not (units := projects[0].UnitsInContext):
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user