mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 19:54:07 +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)
|
||||
|
||||
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
|
||||
for unit in units[0].Units:
|
||||
for unit in assignment.Units:
|
||||
if unit.is_a("IfcNamedUnit") and unit.UnitType == "LENGTHUNIT":
|
||||
if unit.is_a("IfcSIUnit"):
|
||||
bpy.context.scene.unit_settings.system = "METRIC"
|
||||
|
||||
@@ -116,9 +116,9 @@ class Unit(bonsai.core.tool.Unit):
|
||||
for unit_class in ["IfcDerivedUnit", "IfcMonetaryUnit", "IfcNamedUnit"]:
|
||||
units += tool.Ifc.get().by_type(unit_class)
|
||||
|
||||
assigned_units = tool.Ifc.get().by_type("IfcUnitAssignment")
|
||||
if assigned_units:
|
||||
assigned_units = assigned_units[0].Units
|
||||
assigned_units = []
|
||||
if assignment := tool.Ifc.get().by_type("IfcProject")[0].UnitsInContext:
|
||||
assigned_units = assignment.Units
|
||||
|
||||
for unit in units:
|
||||
name = ""
|
||||
@@ -162,8 +162,7 @@ class Unit(bonsai.core.tool.Unit):
|
||||
|
||||
@classmethod
|
||||
def get_project_currency_unit(cls) -> Union[ifcopenshell.entity_instance, None]:
|
||||
unit_assignments = tool.Ifc.get().by_type("IfcUnitAssignment")
|
||||
for assignment in unit_assignments:
|
||||
if assignment := tool.Ifc.get().by_type("IfcProject")[0].UnitsInContext:
|
||||
for unit in assignment.Units:
|
||||
if unit.is_a("IfcMonetaryUnit"):
|
||||
return unit
|
||||
|
||||
Reference in New Issue
Block a user