I am writing an addon that uses linked libraries. In order to refresh the linked node groups you need to close and reopen blender. I am using some code from the Amaranth addon that I modified. Normally Amaranth prompts the user to save if they haven't yet. I would rather the the file be auto saved in a temp file, closed, then reopened. I have all of this functionality done.
My problem lies with the fact that now when the user goes to save it will save the temp file. I want to know if there is a way to clear the location it will save in?
I found bpy.data.filepath
but it is read-only. I need a way to clear this so when a user presses CTRL + S it doesn't save in a weird location.
My operator is here:
class NGLRefresh(Operator):
bl_label = "Refresh"
bl_idname = "ngl.refresh"
bl_description = "Relinks the nodes from the library file (saves and reloads)"
temp_path = bpy.utils.script_path_user() + os.sep + "NGL_TEMP_FILE.blend"
# A huge thanks to Pablo Vazquez
# for the code from Amaranth (https://github.com/venomgfx/amaranth)
def save_reload(self, context, path):
if not path:
bpy.ops.wm.save_as_mainfile(filepath=self.temp_path)
bpy.ops.wm.open_mainfile(filepath=self.temp_path)
return
bpy.ops.wm.save_mainfile()
self.report({"INFO"}, "Saved & Reloaded")
bpy.ops.wm.open_mainfile("EXEC_DEFAULT", filepath=path)
def execute(self, context):
path = bpy.data.filepath
self.save_reload(context, path)
# Remove temp file if necessary
if os.path.exists(self.temp_path):
os.remove(self.temp_path)
return {"FINISHED"}