From 37ab9c80e3bc34620e08199e9026344241bbd495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Tue, 17 Oct 2023 18:45:14 -0300 Subject: [PATCH] Duplication now recreates connections path #3770 --- .../bim/module/geometry/operator.py | 8 +++-- src/blenderbim/blenderbim/tool/root.py | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 3786206c47..1388111994 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -752,7 +752,8 @@ class OverrideDuplicateMove(bpy.types.Operator): self.new_active_obj = None # Track decompositions so they can be recreated after the operation - relationships = tool.Root.get_decomposition_relationships(objects_to_duplicate) + decomposition_relationships = tool.Root.get_decomposition_relationships(objects_to_duplicate) + connection_relationships = tool.Root.get_connection_relationships(objects_to_duplicate) old_to_new = {} for obj in objects_to_duplicate: @@ -811,11 +812,12 @@ class OverrideDuplicateMove(bpy.types.Operator): if old.is_a("IfcElementAssembly"): OverrideDuplicateMove.recreate_assembly(old_to_new) - # Remove connections with old objects + # Remove connections with old objects and recreates paths OverrideDuplicateMove.remove_old_connections(old_to_new) + tool.Root.recreate_connections(connection_relationships, old_to_new) # Recreate decompositions - tool.Root.recreate_decompositions(relationships, old_to_new) + tool.Root.recreate_decompositions(decomposition_relationships, old_to_new) blenderbim.bim.handler.refresh_ui_data() @staticmethod diff --git a/src/blenderbim/blenderbim/tool/root.py b/src/blenderbim/blenderbim/tool/root.py index ce198c9f00..0dc657353f 100644 --- a/src/blenderbim/blenderbim/tool/root.py +++ b/src/blenderbim/blenderbim/tool/root.py @@ -89,6 +89,26 @@ class Root(blenderbim.core.tool.Root): relationships[element] = {"type": "fill", "element": building} return relationships + @classmethod + def get_connection_relationships(cls, objs): + relationships = {} + for obj in objs: + element = tool.Ifc.get_entity(obj) + if not element: + continue + if hasattr(element, "ConnectedTo") and element.ConnectedTo: + paths = [connection for connection in element.ConnectedTo if connection.is_a("IfcRelConnectsPathElements")] + for path in paths: + relationships[element] = {"type": "path", + "related_connection_type": path.RelatedConnectionType, + "related_element": path.RelatedElement, + "related_priorities": path.RelatedPriorities, + "relating_connection_type": path.RelatingConnectionType, + "relating_element": path.RelatingElement, + "relating_priorities": path.RelatingPriorities, + } + return relationships + @classmethod def get_element_representation(cls, element, context): if context.is_a("IfcGeometricRepresentationSubContext"): @@ -197,6 +217,21 @@ class Root(blenderbim.core.tool.Root): should_sync_changes_first=False, ) + @classmethod + def recreate_connections(cls, relationship, old_to_new): + for element, data in relationship.items(): + new_relating_element = old_to_new.get(data["relating_element"])[0] + new_related_element = old_to_new.get(data["related_element"])[0] + ifcopenshell.api.run( + "geometry.connect_path", + tool.Ifc.get(), + relating_element=new_relating_element, + related_element=new_related_element, + relating_connection=data["relating_connection_type"], + related_connection=data["related_connection_type"], + ) + + @classmethod def run_geometry_add_representation( cls, obj=None, context=None, ifc_representation_class=None, profile_set_usage=None