If I have a basic save/export operator like this:
class SaveData(bpy.types.Operator):
bl_idname = "my.save"
bl_label = "Save"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
do_save(ensure_ext(self.filepath, ".mytype"))
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
What is the right/idiomatic way to prevent that that from saving a file named .mytype if the user just hits Save without supplying a filename? This bad behavior appears to be common behavior among many Blender plugins (whether they give a Python traceback or save a .ext file just depends on whether they happen to call ensure_ext() or something similar)
What I have tried:
- The
checkmethod is not clearly documented, but it appears to be for checking parameters beforeinvoke, not after. - The
executemethod could check for emptyself.filepathbut I've found zero examples of that. This would occur after the file selector has closed, so it would require popping another modal to warn the user that nothing happened. - The native Save/Save As for
.blendfiles aggressively puts.blendinto the filepath if you try to clear it, so I guess technically you can't save with no filename, but it will happily write a file named.blend. There also doesn't seem to be any way to turn on that behavior for other file selectors. - The
FILE_OT_execute(which is the operator for theSaveorLoadbutton in the file selector) has a promising property namedneed_activewhich looks (from reading the C source) like it makes the button do nothing in case no file is selected. But I don't understand how I would set that property because that is used internally byfileselect_add(). This behavior would match other Windows programs I've tested.