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.
Here is the code for the script.
import arcpy MXD=arcpy.mapping.MapDocument('CURRENT') dataframe = arcpy.mapping.ListDataFrames(MXD, "US Data") dataframe.zoomToSelectedFeatures() arcpy.RefreshActiveView()
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 MXD=mapping.MapDocument('CURRENT') dataframe = mapping.ListDataFrames(MXD, "US Data") dataframe.zoomToSelectedFeatures() RefreshActiveView()
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 MXD=arcpy.mapping.MapDocument('CURRENT') dataframe = arcpy.mapping.ListDataFrames(MXD, "US Data") dataframe.zoomToSelectedFeatures() arcpy.RefreshActiveView()
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?