I thought this got documented. Since it's undocumented, it's not officially supported, so your mileage may vary, not responsible for damage, etc.
filter
is a callable that returns a True
/False
value as to whether the path specified can be saved to or opened (in the case of OpenDialog
). filter_label
is what shows up in the filter text in the dialog below the filename text box. If you don't specify filter_label
, it will call str(filter)
and use that.
As an example:
save_folder = os.path.dirname(arcpy.mapping.MapDocument('current').filePath or os.getcwd())
def save_mxd(filename):
if not filename:
return False
if os.path.splitext(filename)[1].lower() == ".mxd":
return True
return False
save_path = SaveDialog("Save a map document", "Map document", save_folder, save_mxd, "Mxd Files (*.mxd)")
Or you could be terse and use a lambda:
save_path = SaveDialog("Save", "MXD", "", lambda x: x and x.lower().endswith('.mxd'), "MXDs")
Since the Dialog function just calls whatever it's passed with one argument, you can get fancy and use a class:
class FileGDBSave(object):
def __str__(self):
return "New Feature Class in a File GDB"
def __call__(self, out_path):
if out_path:
out_dir = os.path.dirname(out_path)
extension = os.path.splitext(out_dir)[1].lower()
# Writing to a File Geodatabase (folder name ends with .gdb)
if os.path.isdir(out_dir) and extension == ".gdb":
# Feature class doesn't exist yet
if not arcpy.Exists(out_path):
return True
return False
out_path = pythonaddins.SaveDialog("Save new feature class",
"Feature class",
os.path.dirname(
arcpy.mapping.MapDocument("current").filePath),
FileGDBSave())
Note here the __str__
method is implemented to provide the filter label and the __call__
method acts as what gets passed the path name for determining if the file can be saved at the specified path.