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

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

Python scripting help

Postby Oceans14 » Fri Feb 17, 2017 6:11 pm

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: Select all
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!

Jedi High Council
User avatar
Posts: 2306
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

Postby Twilight_Warrior » Sat Feb 18, 2017 4:32 pm

You're missing

import threading
import time

Timer is a threading object.

Return to Technical Advice and Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests