Closes ##7225 - Improve generate_freestyle_linework to robustly handle SVG output by falling back to the first generated linework file if the expected file is missing.

This commit is contained in:
Ryan Schultz
2025-10-10 17:28:15 -05:00
parent 60d85b4259
commit 89c039252b
@@ -17,6 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import os
import glob
import bpy
import json
import time
@@ -794,11 +795,14 @@ class CreateDrawing(bpy.types.Operator):
edge_bm.to_mesh(edge_mesh)
edge_bm.free()
actual_path = svg_path[0:-4] + "0001.svg"
context.scene.render.filepath = svg_path[0:-4]
bpy.ops.render.render(write_still=False)
pattern = svg_path[0:-4] + "????.svg"
files = glob.glob(pattern)
if not files:
self.report({"ERROR"}, f"No Freestyle SVG found matching {pattern}")
return None
os.replace(actual_path, svg_path)
found_path = max(files, key=os.path.getctime)
os.replace(found_path, svg_path)
bpy.data.objects.remove(edge_obj)
bpy.data.meshes.remove(edge_mesh)