I have written an application that does a lot of geoprocessing using arcpy. Once started, the application itself runs at an acceptable speed, but it is very slow to boot. It can take 30 seconds or so to start up the GUI, so I'd like to find ways to make it start faster.
As far as I can tell, the main source of delay is when I set the dataframe as follows:
self.df = arcpy.mapping.ListDataFrames(self.mxd, "")
Does anyone have any tips / tricks to make either the whole application or the ListDataFrames run quicker when the application is started?
I use ArcGIS 10.1, python 2.7 and tkinter for the GUI. Feel free to ask if I've forgotten to mention anything.
As requested, here is the (very!) stripped down version of the start my code:
import arcpy import sys from Tkinter import * import ttk import tkMessageBox import tkFileDialog import webbrowser import time import csv import os import textwrap arcpy.env.workspace = r".\..\Append\temp.gdb" Title = "Automated Map Generator" class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master, background = "white") self.grid() self.createWidgets(master) def createWidgets(self, master): # setup map document self.mxd = arcpy.mapping.MapDocument(r".\autolim_mapping.mxd") arcpy.env.overwriteOutput = True self.df = arcpy.mapping.ListDataFrames(self.mxd, "") #[Lots of missing code here] root = Tk() root.tkraise() app = Application(master=root) app.master.title(Title) app.mainloop()
How do I know what it's the ListDataFrames that takes so long? I put a whole heap of print statements through the startup code and noted how long they took to come out... I bet there are better ways to do this, but I'm pretty new to python.
EDIT 2: @dassouki - thanks! Here are the output times from after 'import time':
Start Class Application (Frame): 1.53200006485 Start def Create Widgets: 1.59400010109 Start mapping.MapDocument: 1.6099998951 Start env.overwrite: 1.64100003242 Start mapping.ListDataFrames: 1.64100003242 Finish mapping.ListDataFrames: 12.2660000324