aggregate data - small optimization

check for first BBIM_Linked_Aggregate instead of iterating over all rels
This commit is contained in:
Andrej730
2024-10-15 14:30:36 +05:00
parent a76e802ab4
commit 1facba797d
2 changed files with 17 additions and 13 deletions
+16 -12
View File
@@ -19,6 +19,7 @@
import bpy
import bonsai.tool as tool
import ifcopenshell.util.element
from typing import Union
def refresh():
@@ -68,23 +69,26 @@ class AggregateData:
return bool(cls.get_related_objects())
@classmethod
def total_linked_aggregate(cls):
def total_linked_aggregate(cls) -> Union[int, None]:
element = tool.Ifc.get_entity(bpy.context.active_object)
aggregate = ifcopenshell.util.element.get_aggregate(element)
if not aggregate:
return []
return
if not element:
return []
return
product_linked_agg_group = [
r
for r in getattr(aggregate, "HasAssignments", []) or []
if r.is_a("IfcRelAssignsToGroup")
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
]
product_linked_agg_group = next(
(
r
for r in getattr(aggregate, "HasAssignments", []) or []
if r.is_a("IfcRelAssignsToGroup")
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
),
None,
)
if not product_linked_agg_group:
return []
if product_linked_agg_group is None:
return
total = len(product_linked_agg_group[0].RelatedObjects)
total = len(product_linked_agg_group.RelatedObjects)
return total
+1 -1
View File
@@ -140,7 +140,7 @@ class BIM_PT_linked_aggregate(Panel):
else:
row.label(text=f"{Number_Linked_Aggregates} Linked Aggregates")
op = row.operator("bim.duplicate_linked_aggregate_to_3d_cursor", text="", icon="DUPLICATE")
if type(Number_Linked_Aggregates) is int:
if Number_Linked_Aggregates is not None:
if Number_Linked_Aggregates > 0:
op = row.operator("bim.select_linked_aggregates", text="", icon="OUTLINER_DATA_POINTCLOUD")
op.select_parts = False