Skip to content

Commit 51edb20

Browse files
committed
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.
1 parent 8acc238 commit 51edb20

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/bonsai/bonsai/bim/module/spatial/operator.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,33 @@ def invoke(self, context, event):
299299

300300
def execute(self, context):
301301
if self.container:
302-
container = tool.Ifc.get().by_id(self.container)
303-
elif element := tool.Ifc.get_entity(context.active_object):
304-
container = ifcopenshell.util.element.get_container(element)
302+
# Called from container manager panel with explicit container
303+
ifc_container = tool.Ifc.get().by_id(self.container)
304+
containers = {ifc_container.id(): ifc_container} if ifc_container else {}
305305
else:
306+
# Called from 3D viewport — derive containers from all selected objects
307+
containers = {}
308+
for obj in context.selected_objects or [context.active_object]:
309+
element = tool.Ifc.get_entity(obj)
310+
if not element:
311+
continue
312+
container = tool.Spatial.get_container(element)
313+
if container:
314+
containers[container.id()] = container
315+
316+
if not containers:
306317
return {"CANCELLED"}
307-
if not container:
308-
return {"CANCELLED"}
309-
core.select_similar_container(
310-
tool.Spatial,
311-
container=container,
312-
is_recursive=self.is_recursive,
313-
should_unhide=self.should_unhide,
314-
)
318+
319+
for container in containers.values():
320+
tool.Spatial.select_products(
321+
tool.Spatial.get_decomposed_elements(container, self.is_recursive),
322+
unhide=self.should_unhide,
323+
)
324+
325+
result = " + ".join(f'location = "{c.Name}"' for c in containers.values())
326+
bpy.context.window_manager.clipboard = result
327+
self.report({"INFO"}, f"({result}) was copied to the clipboard.")
328+
315329
self.is_recursive = True # <-- forcibly reset
316330
return {"FINISHED"}
317331

0 commit comments

Comments
 (0)