From 744c08e13e43cf76fa4eedaeabe67993738ca724 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 18 Oct 2023 15:45:00 +0500 Subject: [PATCH] bim.switch_representation to switch to exact representation previously it was switching to the first representation that matches the context, so it wasn't possible to switch to the second one if you had more than 1 representation in the same context using always both element and representation in `geometry.import_representation` so it will import the exact representation and not the first one found by `ifcopenshell.geom.create_shape` --- .../blenderbim/bim/module/geometry/operator.py | 16 ++++++++++------ src/blenderbim/blenderbim/tool/geometry.py | 16 ++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 8f4f0a3927..b659ea2a69 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -211,18 +211,22 @@ class SwitchRepresentation(bpy.types.Operator, Operator): should_switch_all_meshes: bpy.props.BoolProperty() def _execute(self, context): - target = tool.Ifc.get().by_id(self.ifc_definition_id).ContextOfItems + target_representation = tool.Ifc.get().by_id(self.ifc_definition_id) + target = target_representation.ContextOfItems is_subcontext = target.is_a("IfcGeometricRepresentationSubContext") for obj in set(context.selected_objects + [context.active_object]): element = tool.Ifc.get_entity(obj) if not element: continue - if is_subcontext: - representation = ifcopenshell.util.representation.get_representation( - element, target.ContextType, target.ContextIdentifier, target.TargetView - ) + if obj == context.active_object: + representation = target_representation else: - representation = ifcopenshell.util.representation.get_representation(element, target.ContextType) + if is_subcontext: + representation = ifcopenshell.util.representation.get_representation( + element, target.ContextType, target.ContextIdentifier, target.TargetView + ) + else: + representation = ifcopenshell.util.representation.get_representation(element, target.ContextType) if not representation: continue core.switch_representation( diff --git a/src/blenderbim/blenderbim/tool/geometry.py b/src/blenderbim/blenderbim/tool/geometry.py index 5e480ade96..fe55d3c590 100644 --- a/src/blenderbim/blenderbim/tool/geometry.py +++ b/src/blenderbim/blenderbim/tool/geometry.py @@ -479,23 +479,19 @@ class Geometry(blenderbim.core.tool.Geometry): element = tool.Ifc.get_entity(obj) settings = ifcopenshell.geom.settings() settings.set(settings.WELD_VERTICES, True) - context = representation.ContextOfItems + if element.is_a("IfcTypeProduct") or not apply_openings: + settings.set(settings.DISABLE_OPENING_SUBTRACTIONS, True) + if context.ContextIdentifier == "Body" and context.TargetView == "MODEL_VIEW": try: - if element.is_a("IfcTypeProduct") or not apply_openings: - shape = ifcopenshell.geom.create_shape(settings, representation) - else: - shape = ifcopenshell.geom.create_shape(settings, element) + shape = ifcopenshell.geom.create_shape(settings, element, representation) except: settings.set(settings.INCLUDE_CURVES, True) - if element.is_a("IfcTypeProduct") or not apply_openings: - shape = ifcopenshell.geom.create_shape(settings, representation) - else: - shape = ifcopenshell.geom.create_shape(settings, element) + shape = ifcopenshell.geom.create_shape(settings, element, representation) else: settings.set(settings.INCLUDE_CURVES, True) - shape = ifcopenshell.geom.create_shape(settings, representation) + shape = ifcopenshell.geom.create_shape(settings, element, representation) ifc_importer = blenderbim.bim.import_ifc.IfcImporter(ifc_import_settings) ifc_importer.file = tool.Ifc.get()