From a14b02d32f9182d493af197770900ef3d167c747 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Wed, 15 Apr 2026 17:07:38 -0500 Subject: [PATCH] Select from multiple containers in select_similar_container Previously only the active object's container was used. Now all selected objects' containers are collected and their decomposed elements selected, with the query copied to the clipboard as location = "A" + location = "B". Generated with the assistance of an AI coding tool. --- .../bonsai/bim/module/spatial/operator.py | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index 86614a6a79..a95365b24e 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -299,19 +299,33 @@ class SelectSimilarContainer(bpy.types.Operator): def execute(self, context): if self.container: - container = tool.Ifc.get().by_id(self.container) - elif element := tool.Ifc.get_entity(context.active_object): - container = ifcopenshell.util.element.get_container(element) + # Called from container manager panel with explicit container + ifc_container = tool.Ifc.get().by_id(self.container) + containers = {ifc_container.id(): ifc_container} if ifc_container else {} else: + # Called from 3D viewport — derive containers from all selected objects + containers = {} + for obj in context.selected_objects or [context.active_object]: + element = tool.Ifc.get_entity(obj) + if not element: + continue + container = tool.Spatial.get_container(element) + if container: + containers[container.id()] = container + + if not containers: return {"CANCELLED"} - if not container: - return {"CANCELLED"} - core.select_similar_container( - tool.Spatial, - container=container, - is_recursive=self.is_recursive, - should_unhide=self.should_unhide, - ) + + for container in containers.values(): + tool.Spatial.select_products( + tool.Spatial.get_decomposed_elements(container, self.is_recursive), + unhide=self.should_unhide, + ) + + result = " + ".join(f'location = "{c.Name}"' for c in containers.values()) + bpy.context.window_manager.clipboard = result + self.report({"INFO"}, f"({result}) was copied to the clipboard.") + self.is_recursive = True # <-- forcibly reset return {"FINISHED"}