Duplication now recreates connections path #3770

This commit is contained in:
Bruno Perdigão
2023-10-17 18:45:14 -03:00
parent f68baee5c3
commit 37ab9c80e3
2 changed files with 40 additions and 3 deletions
@@ -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
+35
View File
@@ -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