mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
bim.select_similar_type optimization
1) avoid selecting elements of the same type multiple times 2) iterate over occurrences of the type rather than visible objects, as it's usually smaller amount of objects
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import bmesh
|
import bmesh
|
||||||
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.schema
|
import ifcopenshell.util.schema
|
||||||
import ifcopenshell.util.type
|
import ifcopenshell.util.type
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
@@ -171,15 +172,22 @@ class SelectSimilarType(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
objects = bpy.context.selected_objects
|
objects = bpy.context.selected_objects
|
||||||
|
|
||||||
|
# store relating types to avoid selecting same elements multiple times
|
||||||
|
relating_types = set()
|
||||||
|
|
||||||
for related_object in objects:
|
for related_object in objects:
|
||||||
relating_type = ifcopenshell.util.element.get_type(tool.Ifc.get_entity(related_object))
|
relating_type = ifcopenshell.util.element.get_type(tool.Ifc.get_entity(related_object))
|
||||||
if not relating_type:
|
if not relating_type:
|
||||||
related_object.select_set(False)
|
related_object.select_set(False)
|
||||||
continue
|
continue
|
||||||
|
relating_types.add(relating_type)
|
||||||
|
|
||||||
|
for relating_type in relating_types:
|
||||||
related_objects = ifcopenshell.util.element.get_types(relating_type)
|
related_objects = ifcopenshell.util.element.get_types(relating_type)
|
||||||
for obj in context.visible_objects:
|
for element in related_objects:
|
||||||
element = tool.Ifc.get_entity(obj)
|
obj = tool.Ifc.get_object(element)
|
||||||
if element and element in related_objects:
|
if obj and obj in context.visible_objects:
|
||||||
obj.select_set(True)
|
obj.select_set(True)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user