Fix #3273. Don't use simple string replacement when renaming drawings but instead identify elements by attributes which is preferred.

This commit is contained in:
Dion Moult
2023-07-29 14:45:59 +10:00
parent 630bb88a15
commit 8be0f2e1da
2 changed files with 15 additions and 8 deletions
+3 -2
View File
@@ -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()
+12 -6
View File
@@ -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):