Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Has anyone else noticed that accessing elements from arcpy.mapping.ListLayoutElements() through a tool script takes longer than within ArcMap? Whether using a specific name, wildcard or nothing, the call takes on the order of 90 seconds or longer to return:

arcpy.AddMessage("  Start: " + str(
mapDoc = arcpy.mapping.MapDocument(mapDocumentPath)
elements = arcpy.mapping.ListLayoutElements(mapDoc, "GRAPHIC_ELEMENT")
arcpy.AddMessage("  Finished: " + str(

Start: 2011-05-24 12:29:28.479000
Finished: 2011-05-24 12:31:10.510000

When the call is made within ArcMap the return is instantaneous.

mapDoc = arcpy.mapping.MapDocument("CURRENT")
elements = arcpy.mapping.ListLayoutElements(mapDoc, "GRAPHIC_ELEMENT")

In both instances, I'm referencing the same map document.

Using ArcGIS 10 SP2.

  1. It may not be obvious but the results are instantaneous when the script is run against "CURRENT". Specify any map document other than "CURRENT" and the script will slow down.
  2. I executed a loop as Jason suggested and found little difference between the first call to ListLayoutElements() and the last. The first selection took 28 seconds while the other nine averaged 24 seconds.
  3. The map document has nine data frames and nine corresponding legend elements that were converted to graphics. When these "legends" are present in the document then ListLayoutElements() is slow; when they're deleted then ListLayoutElements() returns immediately.
share|improve this question
Is background processing enabled or disabled? – Kirk Kuykendall May 24 '11 at 19:46
Kirk, I have both "Always run in foreground" and "Run Python script in process" checked. Is that what you were asking? – Erik Anderson May 25 '11 at 17:39

There were issues with this at 10.0, but we've ironed out all the visible ones in the service packs. You should be seeing a significant improvement in performance on ListLayoutElements and friends using SP2 over SP1 or 10.0. Are subsequent calls to the same function as slow? What if you add the time that it takes to load the document into ArcMap into account? Would that bring the two to something close to one another?

Try this:

arcpy.AddMessage("  Start: " + str(
mapDoc = arcpy.mapping.MapDocument(mapDocumentPath)
for counter in xrange(10):
  elements = arcpy.mapping.ListLayoutElements(mapDoc, "GRAPHIC_ELEMENT")
  arcpy.AddMessage("  Finished %i: %s" % (counter + 1, str(

Outside of ArcMap, the Map Document classes need to set up what is essentially a hardware context to draw to to ensure the metrics of layout elements are correct. This is not necessary in the active ArcMap document because it has the hardware context of the application's window, but it may account to some extent for the speed differences.

share|improve this answer
In the same script, I have one call to loop through all the text elements setting each one as needed and another call for a specific graphic element to move it into place on the page layout. With both calls enabled the script takes 3+ minutes to execute; if the calls are disabled the script executes in less than 20 seconds. That would seem to discount the document loading. – Erik Anderson May 25 '11 at 17:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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