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(datetime.now())) mapDoc = arcpy.mapping.MapDocument(mapDocumentPath) elements = arcpy.mapping.ListLayoutElements(mapDoc, "GRAPHIC_ELEMENT") arcpy.AddMessage(" Finished: " + str(datetime.now())) 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.
- 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.
- 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.
- 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.