mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix #5964. Only get the unit assignment from the project to prevent ambiguity.
I really don't know why I didn't do this before.
This commit is contained in:
@@ -893,9 +893,9 @@ class IfcImporter:
|
|||||||
tool.Loader.set_unit_scale(self.unit_scale)
|
tool.Loader.set_unit_scale(self.unit_scale)
|
||||||
|
|
||||||
def set_units(self):
|
def set_units(self):
|
||||||
if not (units := self.file.by_type("IfcUnitAssignment")):
|
if not (assignment := self.file.by_type("IfcProject")[0].UnitsInContext):
|
||||||
return # Geometry is optional in IFC
|
return # Geometry is optional in IFC
|
||||||
for unit in units[0].Units:
|
for unit in assignment.Units:
|
||||||
if unit.is_a("IfcNamedUnit") and unit.UnitType == "LENGTHUNIT":
|
if unit.is_a("IfcNamedUnit") and unit.UnitType == "LENGTHUNIT":
|
||||||
if unit.is_a("IfcSIUnit"):
|
if unit.is_a("IfcSIUnit"):
|
||||||
bpy.context.scene.unit_settings.system = "METRIC"
|
bpy.context.scene.unit_settings.system = "METRIC"
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ class Unit(bonsai.core.tool.Unit):
|
|||||||
for unit_class in ["IfcDerivedUnit", "IfcMonetaryUnit", "IfcNamedUnit"]:
|
for unit_class in ["IfcDerivedUnit", "IfcMonetaryUnit", "IfcNamedUnit"]:
|
||||||
units += tool.Ifc.get().by_type(unit_class)
|
units += tool.Ifc.get().by_type(unit_class)
|
||||||
|
|
||||||
assigned_units = tool.Ifc.get().by_type("IfcUnitAssignment")
|
assigned_units = []
|
||||||
if assigned_units:
|
if assignment := tool.Ifc.get().by_type("IfcProject")[0].UnitsInContext:
|
||||||
assigned_units = assigned_units[0].Units
|
assigned_units = assignment.Units
|
||||||
|
|
||||||
for unit in units:
|
for unit in units:
|
||||||
name = ""
|
name = ""
|
||||||
@@ -162,8 +162,7 @@ class Unit(bonsai.core.tool.Unit):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_project_currency_unit(cls) -> Union[ifcopenshell.entity_instance, None]:
|
def get_project_currency_unit(cls) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
unit_assignments = tool.Ifc.get().by_type("IfcUnitAssignment")
|
if assignment := tool.Ifc.get().by_type("IfcProject")[0].UnitsInContext:
|
||||||
for assignment in unit_assignments:
|
|
||||||
for unit in assignment.Units:
|
for unit in assignment.Units:
|
||||||
if unit.is_a("IfcMonetaryUnit"):
|
if unit.is_a("IfcMonetaryUnit"):
|
||||||
return unit
|
return unit
|
||||||
|
|||||||
@@ -404,9 +404,7 @@ def get_named_dimensions(name):
|
|||||||
|
|
||||||
|
|
||||||
def get_unit_assignment(ifc_file: ifcopenshell.file) -> Union[ifcopenshell.entity_instance, None]:
|
def get_unit_assignment(ifc_file: ifcopenshell.file) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
unit_assignments = ifc_file.by_type("IfcUnitAssignment")
|
return ifc_file.by_type("IfcProject")[0].UnitsInContext
|
||||||
if unit_assignments:
|
|
||||||
return unit_assignments[0]
|
|
||||||
|
|
||||||
|
|
||||||
def get_project_unit(ifc_file: ifcopenshell.file, unit_type: str) -> Union[ifcopenshell.entity_instance, None]:
|
def get_project_unit(ifc_file: ifcopenshell.file, unit_type: str) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
@@ -641,9 +639,8 @@ 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 not ifc_file.by_type("IfcUnitAssignment"):
|
if not (units := ifc_file.by_type("IfcProject")[0].UnitsInContext):
|
||||||
return 1
|
return 1
|
||||||
units = ifc_file.by_type("IfcUnitAssignment")[0]
|
|
||||||
unit_scale = 1
|
unit_scale = 1
|
||||||
for unit in units.Units:
|
for unit in units.Units:
|
||||||
if not hasattr(unit, "UnitType") or unit.UnitType != unit_type:
|
if not hasattr(unit, "UnitType") or unit.UnitType != unit_type:
|
||||||
|
|||||||
Reference in New Issue
Block a user