From 6300b27ac4f63a3b2a4bb73242a5f0879d4eab9d Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 7 May 2020 21:25:53 +1000 Subject: [PATCH] IFC unit settings are now preserved on import --- .../blenderbim/bim/import_ifc.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index 64ff6275bf..2cee5f49bb 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -227,6 +227,7 @@ class IfcImporter(): if self.ifc_import_settings.should_auto_set_workarounds: self.auto_set_workarounds() self.calculate_unit_scale() + self.set_units() self.create_geometric_representation_contexts() self.create_project() self.create_classifications() @@ -706,7 +707,7 @@ class IfcImporter(): units = self.file.by_type('IfcUnitAssignment')[0] for unit in units.Units: if not hasattr(unit, 'UnitType') \ - or unit.UnitType != 'LENGTHUNIT': + or unit.UnitType != 'LENGTHUNIT': continue while unit.is_a('IfcConversionBasedUnit'): self.unit_scale *= unit.ConversionFactor.ValueComponent.wrappedValue @@ -714,6 +715,24 @@ class IfcImporter(): if unit.is_a('IfcSIUnit'): self.unit_scale *= SIUnitHelper.get_prefix_multiplier(unit.Prefix) + def set_units(self): + units = self.file.by_type('IfcUnitAssignment')[0] + for unit in units.Units: + if unit.UnitType == 'LENGTHUNIT': + if unit.is_a('IfcSIUnit'): + bpy.context.scene.unit_settings.system = 'METRIC' + if unit.Name == 'METRE': + if not unit.Prefix: + bpy.context.scene.unit_settings.length_unit = 'METERS' + else: + bpy.context.scene.unit_settings.length_unit = f'{unit.Prefix}METERS' + else: + bpy.context.scene.unit_settings.system = 'IMPERIAL' + if unit.Name == 'inch': + bpy.context.scene.unit_settings.length_unit = 'INCHES' + elif unit.Name == 'foot': + bpy.context.scene.unit_settings.length_unit = 'FEET' + def create_geometric_representation_contexts(self): bpy.context.scene.BIMProperties.has_model_context = False for context in self.file.by_type('IfcGeometricRepresentationContext'):