From 5e6a094ac68bcfda3b66910bd704f1b5d57d802b Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 24 Apr 2023 22:41:15 +1000 Subject: [PATCH] Fix #3046. Renaming drawings now updates all drawing references on sheets. --- .../blenderbim/bim/module/drawing/operator.py | 2 ++ src/blenderbim/blenderbim/core/drawing.py | 14 +++++++++++--- src/blenderbim/blenderbim/tool/drawing.py | 14 +++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index cc56642829..f115e08ca8 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -871,6 +871,8 @@ class CreateDrawing(bpy.types.Operator): merged_polygons = merged_polygons.geoms elif type(merged_polygons) == shapely.Polygon: merged_polygons = [merged_polygons] + else: + merged_polygons = [] for polygon in merged_polygons: g = etree.Element("g") diff --git a/src/blenderbim/blenderbim/core/drawing.py b/src/blenderbim/blenderbim/core/drawing.py index 9730d49eda..9489a55f8c 100644 --- a/src/blenderbim/blenderbim/core/drawing.py +++ b/src/blenderbim/blenderbim/core/drawing.py @@ -308,9 +308,17 @@ def update_drawing_name(ifc, drawing_tool, drawing=None, name=None): new_location = drawing_tool.get_default_drawing_path(name) if old_location != new_location: ifc.run("document.edit_reference", reference=reference, attributes={"Location": new_location}) - old_location = ifc.resolve_uri(old_location) - if drawing_tool.does_file_exist(old_location): - drawing_tool.move_file(old_location, ifc.resolve_uri(new_location)) + resolved_old_location = ifc.resolve_uri(old_location) + if drawing_tool.does_file_exist(resolved_old_location): + drawing_tool.move_file(resolved_old_location, ifc.resolve_uri(new_location)) + + for reference in drawing_tool.get_references_with_location(old_location): + ifc.run("document.edit_reference", reference=reference, attributes={"Location": new_location}) + sheet = drawing_tool.get_reference_document(reference) + if not sheet: + uri = ifc.resolve_uri(drawing_tool.get_document_uri(sheet, "LAYOUT")) + if drawing_tool.does_file_exist(uri): + drawing_tool.update_embedded_svg_location(uri, old_location, new_location) def add_annotation(ifc, collector, drawing_tool, drawing=None, object_type=None): diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index 6aca2b0b17..7731071b18 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -1289,6 +1289,18 @@ class Drawing(blenderbim.core.tool.Drawing): return document.DocumentReferences or [] return document.HasDocumentReferences or [] + @classmethod + def get_references_with_location(cls, location): + return [r for r in tool.Ifc.get().by_type("IfcDocumentReference") if r.Location == location] + + @classmethod + def update_embedded_svg_location(cls, uri, old_location, new_location): + with open(uri, "r") as f: + svg = f.read() + svg = svg.replace(os.path.basename(old_location), os.path.basename(new_location)) + with open(uri, "w") as f: + f.write(svg) + @classmethod def get_reference_description(cls, reference): return reference.Description @@ -1300,7 +1312,7 @@ class Drawing(blenderbim.core.tool.Drawing): @classmethod def get_reference_element(cls, reference): if tool.Ifc.get_schema() == "IFC2X3": - refs = [r for r in tool.Ifc.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference] + refs = [r for r in tool.Ifc.get().by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference] else: refs = reference.DocumentRefForObjects if refs: