IFC Mesh Separate - add to object mode menu too for discoverability + support multiple selected elements

Short demo - https://imgur.com/a/PIuJ9Rq
This commit is contained in:
Andrej730
2025-04-24 19:54:27 +05:00
parent 529c74f6a9
commit 52af302bef
2 changed files with 9 additions and 8 deletions
@@ -103,11 +103,10 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
non_ifc_objects: list[bpy.types.Object] = [] non_ifc_objects: list[bpy.types.Object] = []
if len(context.selected_editable_objects) > 1: selected_objects = context.selected_editable_objects
self.report({"ERROR"}, "Separate for multiple elements is not yet supported. Select just 1.") bpy.ops.object.select_all(action="DESELECT")
return {"CANCELLED"}
for obj in context.selected_editable_objects: for obj in selected_objects:
if tool.Geometry.is_representation_item(obj): if tool.Geometry.is_representation_item(obj):
self.separate_item(context, obj) self.separate_item(context, obj)
elif element := tool.Ifc.get_entity(obj): elif element := tool.Ifc.get_entity(obj):
@@ -120,17 +119,17 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.mesh.separate(type=self.type) bpy.ops.mesh.separate(type=self.type)
def separate_item(self, context: bpy.types.Context, obj: bpy.types.Object) -> None: def separate_item(self, context: bpy.types.Context, obj: bpy.types.Object) -> None:
tool.Blender.set_active_object(obj)
item = tool.Geometry.get_active_representation(obj) item = tool.Geometry.get_active_representation(obj)
representation_obj = tool.Geometry.get_geometry_props().representation_obj representation_obj = tool.Geometry.get_geometry_props().representation_obj
assert item and representation_obj assert item and representation_obj
if tool.Geometry.is_meshlike_item(item): if tool.Geometry.is_meshlike_item(item):
previous_selected_objects = context.selected_objects
bpy.ops.mesh.separate(type=self.type) bpy.ops.mesh.separate(type=self.type)
for obj in context.selected_objects: for obj_ in context.selected_objects:
if obj in previous_selected_objects: if obj_ == obj:
continue continue
self.add_meshlike_item(obj) self.add_meshlike_item(obj_)
tool.Geometry.reload_representation(representation_obj) tool.Geometry.reload_representation(representation_obj)
else: else:
self.report({"INFO"}, f"Separating an {item.is_a()} is not supported") self.report({"INFO"}, f"Separating an {item.is_a()} is not supported")
@@ -174,6 +173,7 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
) -> None: ) -> None:
# You cannot separate meshes if the representation is mapped. # You cannot separate meshes if the representation is mapped.
relating_type = tool.Root.get_element_type(element) relating_type = tool.Root.get_element_type(element)
tool.Blender.set_active_object(obj)
if relating_type and tool.Root.does_type_have_representations(relating_type): if relating_type and tool.Root.does_type_have_representations(relating_type):
# We toggle edit mode to ensure that once representations are # We toggle edit mode to ensure that once representations are
# unmapped, our Blender mesh only has a single user. # unmapped, our Blender mesh only has a single user.
@@ -64,6 +64,7 @@ def object_menu(self, context):
self.layout.operator("bim.override_object_delete", icon="PLUGIN") self.layout.operator("bim.override_object_delete", icon="PLUGIN")
self.layout.operator("bim.override_paste_buffer", icon="PLUGIN") self.layout.operator("bim.override_paste_buffer", icon="PLUGIN")
self.layout.menu("BIM_MT_object_set_origin", icon="PLUGIN") self.layout.menu("BIM_MT_object_set_origin", icon="PLUGIN")
self.layout.menu("BIM_MT_separate", icon="PLUGIN")
def edit_mesh_menu(self, context): def edit_mesh_menu(self, context):