mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +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 bpy
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -68,23 +69,26 @@ class AggregateData:
|
|||||||
return bool(cls.get_related_objects())
|
return bool(cls.get_related_objects())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def total_linked_aggregate(cls):
|
def total_linked_aggregate(cls) -> Union[int, None]:
|
||||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
element = tool.Ifc.get_entity(bpy.context.active_object)
|
||||||
aggregate = ifcopenshell.util.element.get_aggregate(element)
|
aggregate = ifcopenshell.util.element.get_aggregate(element)
|
||||||
if not aggregate:
|
if not aggregate:
|
||||||
return []
|
return
|
||||||
if not element:
|
if not element:
|
||||||
return []
|
return
|
||||||
|
|
||||||
product_linked_agg_group = [
|
product_linked_agg_group = next(
|
||||||
r
|
(
|
||||||
for r in getattr(aggregate, "HasAssignments", []) or []
|
r
|
||||||
if r.is_a("IfcRelAssignsToGroup")
|
for r in getattr(aggregate, "HasAssignments", []) or []
|
||||||
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
|
if r.is_a("IfcRelAssignsToGroup")
|
||||||
]
|
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
if not product_linked_agg_group:
|
if product_linked_agg_group is None:
|
||||||
return []
|
return
|
||||||
|
|
||||||
total = len(product_linked_agg_group[0].RelatedObjects)
|
total = len(product_linked_agg_group.RelatedObjects)
|
||||||
return total
|
return total
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class BIM_PT_linked_aggregate(Panel):
|
|||||||
else:
|
else:
|
||||||
row.label(text=f"{Number_Linked_Aggregates} Linked Aggregates")
|
row.label(text=f"{Number_Linked_Aggregates} Linked Aggregates")
|
||||||
op = row.operator("bim.duplicate_linked_aggregate_to_3d_cursor", text="", icon="DUPLICATE")
|
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:
|
if Number_Linked_Aggregates > 0:
|
||||||
op = row.operator("bim.select_linked_aggregates", text="", icon="OUTLINER_DATA_POINTCLOUD")
|
op = row.operator("bim.select_linked_aggregates", text="", icon="OUTLINER_DATA_POINTCLOUD")
|
||||||
op.select_parts = False
|
op.select_parts = False
|
||||||
|
|||||||
Reference in New Issue
Block a user