From 00bf08c220d5f86691492163633ac8e7a6f84f2a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 4 Aug 2021 20:45:46 +1000 Subject: [PATCH] Walls are now dynamically voided when joining, so you can join/unjoin voided walls --- .../blenderbim/bim/module/model/__init__.py | 1 + .../blenderbim/bim/module/model/product.py | 31 +++++++++++++++++++ .../blenderbim/bim/module/model/wall.py | 20 ++---------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/__init__.py b/src/blenderbim/blenderbim/bim/module/model/__init__.py index 944583776f..5227400c96 100644 --- a/src/blenderbim/blenderbim/bim/module/model/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/model/__init__.py @@ -4,6 +4,7 @@ from . import handler, prop, ui, grid, product, wall, slab, stair, door, window, classes = ( product.AddTypeInstance, product.AlignProduct, + product.DynamicallyVoidProduct, workspace.Hotkey, wall.JoinWall, wall.AlignWall, diff --git a/src/blenderbim/blenderbim/bim/module/model/product.py b/src/blenderbim/blenderbim/bim/module/model/product.py index b23c5ac4a3..7374d66e67 100644 --- a/src/blenderbim/blenderbim/bim/module/model/product.py +++ b/src/blenderbim/blenderbim/bim/module/model/product.py @@ -120,6 +120,37 @@ class AlignProduct(bpy.types.Operator): return results +class DynamicallyVoidProduct(bpy.types.Operator): + bl_idname = "bim.dynamically_void_product" + bl_label = "Dynamically Void Product" + bl_options = {"REGISTER", "UNDO"} + obj: bpy.props.StringProperty() + + def execute(self, context): + obj = bpy.data.objects.get(self.obj) + product = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) + if not product.HasOpenings: + return {"FINISHED"} + if [m for m in obj.modifiers if m.type == "BOOLEAN"]: + return {"FINISHED"} + representation = ifcopenshell.util.representation.get_representation(product, "Model", "Body", "MODEL_VIEW") + if not representation: + return {"FINISHED"} + was_edit_mode = obj.mode == "EDIT" + if was_edit_mode: + bpy.ops.object.mode_set(mode="OBJECT") + bpy.ops.bim.switch_representation( + obj=obj.name, + should_switch_all_meshes=True, + should_reload=True, + ifc_definition_id=representation.id(), + disable_opening_subtractions=True, + ) + if was_edit_mode: + bpy.ops.object.mode_set(mode="EDIT") + return {"FINISHED"} + + def generate_box(usecase_path, ifc_file, settings): box_context = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Box", "MODEL_VIEW") if not box_context: diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index 756dbb1a67..f5e58c0fc2 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -33,23 +33,7 @@ def mode_callback(obj, data): parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") if not parametric or parametric["Engine"] != "BlenderBIM.DumbWall": return - if product.HasOpenings: - if [m for m in obj.modifiers if m.type == "BOOLEAN"]: - continue - representation = ifcopenshell.util.representation.get_representation( - product, "Model", "Body", "MODEL_VIEW" - ) - if not representation: - continue - bpy.ops.object.mode_set(mode='OBJECT') - bpy.ops.bim.switch_representation( - obj=obj.name, - should_switch_all_meshes=True, - should_reload=True, - ifc_definition_id=representation.id(), - disable_opening_subtractions=True, - ) - bpy.ops.object.mode_set(mode='EDIT') + bpy.ops.bim.dynamically_void_product(obj=obj.name) IfcStore.edited_objs.add(obj) bm = bmesh.from_edit_mesh(obj.data) bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges) @@ -103,6 +87,8 @@ class JoinWall(bpy.types.Operator): def execute(self, context): selected_objs = context.selected_objects + for obj in selected_objs: + bpy.ops.bim.dynamically_void_product(obj=obj.name) if len(selected_objs) == 0: return {"FINISHED"} if not self.join_type: