I have an operator that needs the file to be saved before it can continue (it uploads the file but that's not relevant). Rather than just give an error message that the user needs to save the file first I would like to invoke the default save operator (with the confirmation dialog).
E.g.
import bpy
class TestOperator(bpy.types.Operator):
bl_idname = "custom.test_operator"
def execute(self, context):
do_stuff_with_file()
def invoke(self, context, event):
if bpy.data.is_dirty:
return bpy.ops.wm.save_mainfile('INVOKE_DEFAULT')
return self.execute(context)
But in the example above execute() will never get called if the file is unsaved. Is there a way invoke save_mainfile with the default confirm popup and have execute() run after it's finished?
I could do something like this:
import bpy
class TestOperator(bpy.types.Operator):
bl_idname = "custom.test_operator"
bl_label = "Save File?"
def execute(self, context):
if bpy.data.is_dirty:
bpy.ops.wm.save_mainfile()
do_stuff_with_file()
def invoke(self, context, event):
if bpy.data.is_dirty:
return context.window_manager.invoke_confirm(self, event)
return self.execute(context)
But that doesn't use the same confirm as the save operator, I'd like it to show the path it'd overwrite and use the file browser if you're not editing a file.
invoke_confirmto create a dialog box asking the user if they want to save. What I'm looking for is a way to callexecute()on the main operator afterexecute()has been called onbpy.ops.wm.save_mainfile(which is called as soon as the user confirms to save). – Isaac Nov 21 '17 at 01:19