Page 1 of 1

Python scripting help

Posted: Fri Feb 17, 2017 6:11 pm
by Oceans14
I'm creating a python addon for ArcMap, one of the programs I use heavily for my major. The purpose of the script is to autosave the document periodically in the event of a hang or crash (which is somewhat common since the program deals with extremely large map files and datasets). In any event, I've pieced together the script, but my knowledge of coding is limited to lua and even then I'm not that great. If somebody who knows python could look this over and give me some pointers on the syntax, I would be very grateful.
Hidden/Spoiler:
[code]import arcpy
import pythonaddins

class Autosave(object):
"""Implementation for Scripts_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
pass
def mapsChanged(self):
pass
def saver():
mxd = arcpy.mapping.MapDocument("CURRENT") #targets the currently open map for saving
mxd.save() #actually does the save
print "saved successfully" #and maybe a timestamp? But anyway

t = Timer(120.0, saver) #seems wrong syntax

if mapsChanged(): #is that proper syntax? We'll soon find out.
t.start() #after 120 seconds, the map will be saved. This can be changed depending on how long you want.
else:
return
[/code]
PS - This is not a project for class, its just my attempt at making a utility that has some practical use. Thanks for reading!

Re: Python scripting help

Posted: Sat Feb 18, 2017 4:32 pm
by Twilight_Warrior
You're missing

import threading
import time

Timer is a threading object.