diff --git a/src/blenderbim/blenderbim/core/drawing.py b/src/blenderbim/blenderbim/core/drawing.py index 12bfcf0950..6cc977c67c 100644 --- a/src/blenderbim/blenderbim/core/drawing.py +++ b/src/blenderbim/blenderbim/core/drawing.py @@ -328,8 +328,9 @@ def update_drawing_name(ifc, drawing_tool, drawing=None, name=None): if old_location != new_location: ifc.run("document.edit_reference", reference=reference, attributes={"Location": new_location}) resolved_old_location = ifc.resolve_uri(old_location) + resolved_new_location = ifc.resolve_uri(new_location) if drawing_tool.does_file_exist(resolved_old_location): - drawing_tool.move_file(resolved_old_location, ifc.resolve_uri(new_location)) + drawing_tool.move_file(resolved_old_location, resolved_new_location) for reference in drawing_tool.get_references_with_location(old_location): ifc.run("document.edit_reference", reference=reference, attributes={"Location": new_location}) @@ -337,7 +338,7 @@ def update_drawing_name(ifc, drawing_tool, drawing=None, name=None): if 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) + drawing_tool.update_embedded_svg_location(uri, reference, resolved_new_location) if drawing_tool.is_editing_sheets(): drawing_tool.import_sheets() diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index f38dd0a424..4059dab70f 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -40,6 +40,7 @@ import blenderbim.bim.module.drawing.annotation as annotation import blenderbim.bim.module.drawing.helper as helper from blenderbim.bim.module.drawing.data import FONT_SIZES, DecoratorData from blenderbim.bim.module.drawing.prop import get_diagram_scales, BOX_ALIGNMENT_POSITIONS, ANNOTATION_TYPES_DATA +from lxml import etree from mathutils import Vector from fractions import Fraction import collections @@ -1381,12 +1382,17 @@ class Drawing(blenderbim.core.tool.Drawing): 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) + def update_embedded_svg_location(cls, uri, reference, new_location): + tree = etree.parse(uri) + root = tree.getroot() + rel_location = os.path.relpath(new_location, os.path.dirname(uri)) + + for g in root.findall('.//{http://www.w3.org/2000/svg}g[@data-type="drawing"][@data-id="' + str(reference.id()) + '"]'): + for foreground in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="foreground"]'): + foreground.attrib['{http://www.w3.org/1999/xlink}href'] = rel_location + for background in g.findall('.//{http://www.w3.org/2000/svg}image[@data-type="background"]'): + background.attrib['{http://www.w3.org/1999/xlink}href'] = rel_location[0:-4] + "-underlay.png" + tree.write(uri, pretty_print=True, xml_declaration=True, encoding="utf-8") @classmethod def get_reference_description(cls, reference):