fix #3959 - drawing boundary changes are reflected on bim.create_sheets as well.

and only updates drawings that have been changed
This commit is contained in:
Ryan Schultz
2024-09-07 15:35:05 -05:00
parent 5363c33888
commit fe317f9231
2 changed files with 24 additions and 17 deletions
@@ -1568,6 +1568,10 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator):
active_sheet = props.sheets[props.active_sheet_index]
sheet = tool.Ifc.get().by_id(active_sheet.ifc_definition_id)
# Update any drawing boundary changes
sheet_builder = sheeter.SheetBuilder()
sheet_builder.update_sheet_drawing_sizes(sheet)
if not sheet.is_a("IfcDocumentInformation"):
return
+20 -17
View File
@@ -153,26 +153,29 @@ class SheetBuilder:
drawing_path = tool.Drawing.get_document_uri(tool.Drawing.get_drawing_reference(drawing))
drawing_tree = ET.parse(drawing_path)
drawing_root = drawing_tree.getroot()
view_width = self.convert_to_mm(drawing_root.attrib.get("width"))
view_height = self.convert_to_mm(drawing_root.attrib.get("height"))
view_width = round(self.convert_to_mm(drawing_root.attrib.get("width")), 2)
view_height = round(self.convert_to_mm(drawing_root.attrib.get("height")), 2)
foreground = drawing_view.find(f'.//{SVG}image[@data-type="foreground"]')
height = float(foreground.attrib["height"])
width = float(foreground.attrib["width"])
readjust = Vector((width - view_width, height - view_height)) / 2
current_width = round(float(foreground.attrib["width"]), 2)
current_height = round(float(foreground.attrib["height"]), 2)
for image in drawing_view.findall(f"{SVG}image"):
x = float(image.attrib["x"])
y = float(image.attrib["y"])
if image.attrib["data-type"] == "view-title":
image.attrib["x"] = str(x + readjust.x)
# negate y offset because view-title comes AFTER foreground
image.attrib["y"] = str(y - readjust.y)
else:
image.attrib["x"] = str(x + readjust.x)
image.attrib["y"] = str(y + readjust.y)
image.attrib["width"] = str(view_width)
image.attrib["height"] = str(view_height)
# Check if the dimensions have changed
if current_width != view_width or current_height != view_height:
readjust = Vector((current_width - view_width, current_height - view_height)) / 2
for image in drawing_view.findall(f"{SVG}image"):
x = float(image.attrib["x"])
y = float(image.attrib["y"])
if image.attrib["data-type"] == "view-title":
image.attrib["x"] = str(x + readjust.x)
# negate y offset because view-title comes AFTER foreground
image.attrib["y"] = str(y - readjust.y)
else:
image.attrib["x"] = str(x + readjust.x)
image.attrib["y"] = str(y + readjust.y)
image.attrib["width"] = str(view_width)
image.attrib["height"] = str(view_height)
layout_tree.write(layout_path)