Python scripting help

How To's, Questions, and Solutions for problems. This covers anything from computer hardware problems to software recommendations to tutorials for various software programs.

Note: Neither Gametoast nor any of its members/visitors are responsible for any damage to your computer as a result from advice given in this forum. Follow advice at your own risk and be sure to back up any important files.

Moderator: Moderators

Post Reply
User avatar
Command Sergeant Major
Command Sergeant Major
Posts: 296
Joined: Mon Apr 27, 2015 7:09 pm
Projects :: Athenova Campaign
Games I'm Playing :: SWBF2
Location: Planet 4546b

Python scripting help

Post 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.
[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):
def mapsChanged(self):
def saver():
mxd = arcpy.mapping.MapDocument("CURRENT") #targets the currently open map for saving #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.
PS - This is not a project for class, its just my attempt at making a utility that has some practical use. Thanks for reading!
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2002
Joined: Sat Nov 15, 2008 1:57 pm
Projects :: I should probably start one...
Games I'm Playing :: TOR AC
xbox live or psn: ShadowScorch88

Re: Python scripting help

Post by Twilight_Warrior »

You're missing

import threading
import time

Timer is a threading object.
Post Reply