diff --git a/src/blenderbim/blenderbim/bim/module/model/__init__.py b/src/blenderbim/blenderbim/bim/module/model/__init__.py index 802d4b7a20..944583776f 100644 --- a/src/blenderbim/blenderbim/bim/module/model/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/model/__init__.py @@ -10,6 +10,7 @@ classes = ( wall.FlipWall, wall.SplitWall, wall.AddWallOpening, + slab.AddSlabOpening, prop.BIMModelProperties, ui.BIM_PT_authoring, ui.BIM_PT_authoring_architectural, diff --git a/src/blenderbim/blenderbim/bim/module/model/slab.py b/src/blenderbim/blenderbim/bim/module/model/slab.py index 26b47def02..9aefba63c7 100644 --- a/src/blenderbim/blenderbim/bim/module/model/slab.py +++ b/src/blenderbim/blenderbim/bim/module/model/slab.py @@ -195,6 +195,44 @@ def calculate_quantities(usecase_path, ifc_file, settings): PsetData.load(ifc_file, obj.BIMObjectProperties.ifc_definition_id) +class AddSlabOpening(bpy.types.Operator): + bl_idname = "bim.add_slab_opening" + bl_label = "Add Slab Opening" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): + selected_objs = context.selected_objects + if len(selected_objs) == 0 or not context.active_object: + return {"FINISHED"} + slab_obj = context.active_object + if not slab_obj.BIMObjectProperties.ifc_definition_id: + return {"FINISHED"} + slab = IfcStore.get_file().by_id(slab_obj.BIMObjectProperties.ifc_definition_id) + if not slab.is_a("IfcSlab"): + return {"FINISHED"} + local_location = slab_obj.matrix_world.inverted() @ context.scene.cursor.location + raycast = slab_obj.closest_point_on_mesh(local_location, distance=0.01) + if not raycast[0]: + return {"FINISHED"} + bpy.ops.mesh.primitive_cube_add(size=slab_obj.dimensions[2] * 2) + opening = bpy.context.selected_objects[0] + + # Place the opening in the middle of the slab + global_location = slab_obj.matrix_world @ raycast[1] + normal = raycast[2] + normal.negate() + global_normal = slab_obj.matrix_world.to_quaternion() @ normal + opening.location = global_location + (global_normal * (slab_obj.dimensions[2] / 2)) + + opening.rotation_euler = slab_obj.rotation_euler + opening.name = "Opening" + bpy.ops.bim.add_opening(opening=opening.name, obj=slab_obj.name) + return {"FINISHED"} + + class DumbSlabGenerator: def __init__(self, relating_type): self.relating_type = relating_type diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index 92ad70346b..761ecb7959 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -42,6 +42,9 @@ class AddWallOpening(bpy.types.Operator): bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): selected_objs = context.selected_objects if len(selected_objs) == 0 or not context.active_object: return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/model/workspace.py b/src/blenderbim/blenderbim/bim/module/model/workspace.py index edc51476ec..164af0ae99 100644 --- a/src/blenderbim/blenderbim/bim/module/model/workspace.py +++ b/src/blenderbim/blenderbim/bim/module/model/workspace.py @@ -97,4 +97,4 @@ class Hotkey(bpy.types.Operator): if self.props.ifc_class == "IfcWallType": bpy.ops.bim.add_wall_opening() elif self.props.ifc_class == "IfcSlabType": - pass + bpy.ops.bim.add_slab_opening()