From 0f1e1bcdae5953183ef6502545b9fd534cf731a4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Jan 2025 22:20:52 +1100 Subject: [PATCH] Fix error adding presets with Python 3.13 A separate name-space from the functions body is cleaner and avoids unlikely but possible errors if names ever conflict. --- scripts/startup/bl_operators/presets.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/startup/bl_operators/presets.py b/scripts/startup/bl_operators/presets.py index ba0308de7b7..15f5a656a3a 100644 --- a/scripts/startup/bl_operators/presets.py +++ b/scripts/startup/bl_operators/presets.py @@ -193,14 +193,17 @@ class AddPresetBase: file_preset = open(filepath, "w", encoding="utf-8") file_preset.write("import bpy\n") + namespace_globals = {"bpy": bpy} + namespace_locals = {} + if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: - exec(rna_path) + exec(rna_path, namespace_globals, namespace_locals) file_preset.write("{:s}\n".format(rna_path)) file_preset.write("\n") for rna_path in self.preset_values: - value = eval(rna_path) + value = eval(rna_path, namespace_globals, namespace_locals) rna_recursive_attr_expand(value, rna_path, 1) file_preset.close()