mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
aggregate data - small optimization
check for first BBIM_Linked_Aggregate instead of iterating over all rels
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user