mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-16 02:24:30 +00:00
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.
This commit is contained in:
@@ -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"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user