From 000245c26c98482bdb3bec84acb6acee12094835 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 14 Dec 2023 16:47:10 +1100 Subject: [PATCH] Nesting collections only generate for element nesting, not port nesting --- src/blenderbim/blenderbim/bim/import_ifc.py | 31 ++++++++++++------- src/blenderbim/blenderbim/tool/collector.py | 3 +- .../ifcopenshell/util/element.py | 10 ++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index dbac12a5a8..923d92937f 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -640,7 +640,7 @@ class IfcImporter: if elements_checked > element_checking_threshold: return if element.ObjectPlacement and element.ObjectPlacement.is_a("IfcLocalPlacement"): - placement = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)[:,3][0:3] + placement = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)[:, 3][0:3] if self.is_point_far_away(placement, is_meters=False): return placement if not self.does_element_likely_have_geometry_far_away(element): @@ -1550,20 +1550,27 @@ class IfcImporter: def create_aggregate_and_nest_collections(self): if self.ifc_import_settings.has_filter: - rel_aggregates = [e.IsDecomposedBy[0] for e in self.elements if e.IsDecomposedBy] - rel_aggregates += [e.Decomposes[0] for e in self.elements if e.Decomposes] - rel_aggregates += [e.IsNestedBy[0] for e in self.elements if e.IsNestedBy] - rel_aggregates += [e.Nests[0] for e in self.elements if e.Nests] - rel_aggregates = set(rel_aggregates) + rel_aggregates = set() + for element in self.elements: + if element.IsDecomposedBy: + rel_aggregates.add(element.IsDecomposedBy[0]) + elif element.Decomposes: + rel_aggregates.add(element.Decomposes[0]) + elif element.IsNestedBy: + if [e for e in element.IsNestedBy[0].RelatedObjects if not e.is_a("IfcPort")]: + rel_aggregates.add(element.IsNestedBy[0]) + elif element.Nests: + rel_aggregates.add(element.Nests[0]) else: rel_aggregates = [ - a - for a in self.file.by_type("IfcRelAggregates") - if a.RelatingObject.is_a("IfcElement") or a.RelatingObject.is_a("IfcElementType") + r + for r in self.file.by_type("IfcRelAggregates") + if r.RelatingObject.is_a("IfcElement") or r.RelatingObject.is_a("IfcElementType") ] + [ - a - for a in self.file.by_type("IfcRelNests") - if a.RelatingObject.is_a("IfcElement") or a.RelatingObject.is_a("IfcElementType") + r + for r in self.file.by_type("IfcRelNests") + if (r.RelatingObject.is_a("IfcElement") or r.RelatingObject.is_a("IfcElementType")) + and [e for e in r.RelatedObjects if not e.is_a("IfcPort")] ] if len(rel_aggregates) > 10000: diff --git a/src/blenderbim/blenderbim/tool/collector.py b/src/blenderbim/blenderbim/tool/collector.py index 9857f19651..841a515cc7 100644 --- a/src/blenderbim/blenderbim/tool/collector.py +++ b/src/blenderbim/blenderbim/tool/collector.py @@ -157,7 +157,8 @@ class Collector(blenderbim.core.tool.Collector): return cls._create_own_collection(obj) if getattr(element, "IsNestedBy", None): - return cls._create_own_collection(obj) + if [e for e in element.IsNestedBy[0].RelatedObjects if not e.is_a("IfcPort")]: + return cls._create_own_collection(obj) @classmethod def _get_collection(cls, element, obj): diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 9cb612c609..46206c3490 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -865,12 +865,16 @@ def get_parts(element): return element.IsDecomposedBy[0].RelatedObjects -def get_components(element): +def get_components(element, include_ports=False): """ Retrieves the components of an element that have an nest relationship. + For nested ports, see ifcopenshell.util.system. + :param element: The IFC element :return: The components of the element + :param include_ports: Default as False. Set to true if you also want to get ports. + :type include_ports: bool,optional Example: @@ -881,7 +885,9 @@ def get_components(element): """ if hasattr(element, "IsNestedBy"): if element.IsNestedBy: - return element.IsNestedBy[0].RelatedObjects + if include_ports: + return element.IsNestedBy[0].RelatedObjects + return [e for e in element.IsNestedBy[0].RelatedObjects if not e.is_a("IfcPort")] elif hasattr(element, "IsDecomposedBy") and element.IsDecomposedBy: if element.IsDecomposedBy[0].is_a("IfcRelNests"): return element.IsDecomposedBy[0].RelatedObjects