diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index 159f157d44..3ab9d60efb 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -27,6 +27,7 @@ import ifcopenshell.api.material import ifcopenshell.api.pset import ifcopenshell.api.root import ifcopenshell.util.element +import ifcopenshell.util.representation import ifcopenshell.util.schema import ifcopenshell.util.shape_builder import ifcopenshell.util.type @@ -530,7 +531,13 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator): return self.report({"WARNING"}, "A featured element must be nominated.") ifc_context = None - if get_enum_items(props, "contexts", context): + if props.ifc_class == "IfcOpeningElement": + ifc_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW") + if ifc_context is None: + ifc_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body") + if ifc_context is None: + self.report({"WARNING"}, "No Model/Body context found. Opening representation may be on the wrong context.") + elif get_enum_items(props, "contexts", context): ifc_context = int(props.contexts or "0") or None if ifc_context: ifc_context = tool.Ifc.get().by_id(ifc_context) diff --git a/src/bonsai/bonsai/bim/module/void/operator.py b/src/bonsai/bonsai/bim/module/void/operator.py index 433ea3a06b..a3c80de072 100644 --- a/src/bonsai/bonsai/bim/module/void/operator.py +++ b/src/bonsai/bonsai/bim/module/void/operator.py @@ -156,6 +156,14 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body_context, ) + if element2: + opening_body_rep = ifcopenshell.util.representation.get_representation(element2, "Model", "Body") + if opening_body_rep is None: + self.report( + {"WARNING"}, + f"Opening '{element2.Name}' has no Body representation — void will not be cut. " + f"Check its context in the IFC file (ContextIdentifier must be 'Body').", + ) ifcopenshell.api.feature.add_feature(tool.Ifc.get(), feature=element2, element=element1) if tool.Ifc.is_moved(obj2):