Save a file with filename prompt from script?

by Ziflin   Last Updated July 13, 2018 01:15 AM

I'm trying to write a simple script to save without Blender showing the confirmation popup. This works fine if the file already has a name, however, if I call bpy.ops.wm.save_mainfile() and the file has not been previously saved, Blender simply crashes/exits completely.

So is there a way to call save_mainfile() so that it behaves the same at the normal File/Save operation where it will prompt the user for a filename? (Note that calling save_as_mainfile() also crashes Blender.

Here's what I was at least hoping would work:

def execute( self, context ):
    if not bpy.data.filepath:
        bpy.ops.wm.save_as_mainfile()
    else:
        bpy.ops.wm.save_mainfile()
    self.report( { 'INFO' }, 'File saved.')
    return { 'FINISHED' }


Related Questions




How to retrieve the thumbnail from a .blend file?

Updated August 17, 2015 17:06 PM

Python: Check if file was saved

Updated July 27, 2016 08:06 AM

How to edit location or rotation of bone in blender?

Updated October 03, 2018 03:15 AM