The engineers I work with have requested an autosave feature for ArcGIS, so I thought I'd make them a python tool that routinely saves. The script works fine when run in the foreground, but fails when "Always run in foreground" in not checked.
The returned messages:
Is there a workaround for this issue?
The code:
"""Autosave"""
import arcpy
import time
import os
arcpy.env.overwriteOutput = True
autosaveFolder = arcpy.GetParameterAsText (0)
autosaveFile = arcpy.GetParameterAsText (1)
waitTime = arcpy.GetParameter (2)
if not autosaveFile.lower().endswith (".mxd"):
autosaveFile = autosaveFile + ".mxd"
waitSeconds = int (waitTime * 60)
autosaveMxd = os.path.join (autosaveFolder, autosaveFile)
while True:
time.sleep (waitSeconds)
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd.saveACopy (autosaveMxd)
del mxd