I do not know if anyone else has this problem but my GPModels that include simple python scripts seem to take way too long to execute. One example is a model I built which is a simple select feature by attribute query and attached at the end of the model is a arcpy script that zooms to the selected feature. alt text

Here is the code for the script.

import arcpy
dataframe = arcpy.mapping.ListDataFrames(MXD, "US Data")[0]

This model will take well over a minute from start to finish which I hope is not be the norm as this is a very simple process. Anyone have any ideas as to why this executes so slow and how to speed it up?

EDIT: The feature class it is doing the sql on is in a file GDB. In the feature class are 1100 points and each point is identified with a STORE number, there is no attribute index on. The sql expression is STORE = '(whatever store number I enter)'. The expression seems simple enough that I doubt it could be the problem. This GDB is on a network drive, could that be the issue, a slow network?

I just tried it again with the data local and it still took just as much time. It must be the python script because the progress box displays "Executing Store Script" for almost the entirety of the time it takes to execute the model, the selection process takes less then a second.

I am running Windows 7 64bit if that matters at all.

I modified the script per a suggestion that the problem might be the amount of time it takes to import all of arcpy, I changed the code to whats listed below and that helped a bit. I still think this takes too long for such a simple task.

from arcpy import mapping, RefreshActiveView
dataframe = mapping.ListDataFrames(MXD, "US Data")[0]

Here is what the dialog box says after the model finishes.

Executing: Model3 ""STORE" =131" Start Time: Wed Nov 10 13:31:35 2010 Executing (Select Layer By Attribute): SelectLayerByAttribute Petm_Str_6_18_10 NEW_SELECTION ""STORE" =131" Start Time: Wed Nov 10 13:31:35 2010 Succeeded at Wed Nov 10 13:31:35 2010 (Elapsed Time: 0.00 seconds) Executing (ZoomToPetm): Script Start Time: Wed Nov 10 13:31:35 2010 Running script Script... Completed script Script... Succeeded at Wed Nov 10 13:31:46 2010 (Elapsed Time: 11.00 seconds) Succeeded at Wed Nov 10 13:31:46 2010 (Elapsed Time: 11.00 seconds)

Update: Exported the enitre model to a python script, cleaned it up and this is what I have now...

import arcpy

# Script arguments
Expression = arcpy.GetParameterAsText(0)
if Expression == '#' or not Expression:
    Expression = "\"STORE\" =" # provide a default value if unspecified

# Local variables:
Stores = Expression
Stores = "US Base Data\\Stores"

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(Stores, "NEW_SELECTION", Expression)

# Process: ZoomTo
dataframe = arcpy.mapping.ListDataFrames(MXD, "US Data")[0]

Using this script only it takes 15 seconds to execute, am I being naive in thinking that this should take a couple (2) seconds to execute at most?

  • 2
    I would say this is not the norm. I set up a nearly identical model that includes your script and it runs in 1 second. This is against a point layer stored locally with 6k points and I'm selecting ~1000 of them. What happens if you specify a different layer? Nov 10, 2010 at 18:41
  • 1
    I'd be surprised if the network is slowing you down that much...try those commands in the python window in ArcMap. Are they still slow? Nov 10, 2010 at 19:06
  • I tried it in the arcpy window and it works almost instantaneousness. Man this is a bugger!
    – Furlong
    Nov 10, 2010 at 21:17
  • It's because of import arcpy. When you run it within ArcGIS, arcpy is pre-loaded; when you run it independently, it's not, and it can take a relatively long time.
    – nmpeterson
    Oct 22, 2014 at 20:55

1 Answer 1


what makes you think that it is the python-part that takes time. without more information it would be more likely that the sql-query part could be optimized. do you have an index on the attribute you are querying on for instance. is there joins involved in the layer-definitions?

run the script without the python-part and see if that executes faster.

if the python-part makes a big difference you should compare with zooming to that feature without the script. maybe it is the rendering whenzooming that takes time.

my point is that you have to narrow the problem in some way, just asking for a faster solution without more information will probably not give very detailed answers.

But one thing to remember: The shortest way is not Arc, it's the straight line. There are alternatives ;-)


  • I added more info based on your comments.
    – Furlong
    Nov 10, 2010 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.