<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ListLayoutElements for loop issue in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638061#M6940</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response Jeff.&amp;nbsp; It is interesting that in some MXDs this is not a problem, and others it is.&amp;nbsp; I thought my MXD was corrupt, so I started a new, very simple MXD. However, when I started adding a graticule, other text and legend elements, etc. I noticed that loop starting to get really slow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, SP2 sounds good... and I'll stop trying to trouble shoot this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Dec 2010 16:16:51 GMT</pubDate>
    <dc:creator>RyanKelley</dc:creator>
    <dc:date>2010-12-01T16:16:51Z</dc:date>
    <item>
      <title>ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638059#M6938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When running my script via ArcToolbox, it takes 1-2 minutes when using the ListLayoutElements for loop. Both when using "TEXT_ELEMENT" and the "MAPSURROUND_ELEMENT". Other for loops are fine (ListLayers).&amp;nbsp; Replacing the text or moving the scale bar is not the problem, it is just the single lines of code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for elm in arcpy.mapping.ListLayoutElements(MXD, "TEXT_ELEMENT"):
&amp;amp; 
for elmScaleBar in arcpy.mapping.ListLayoutElements(MXD, "MAPSURROUND_ELEMENT"):
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why is this happening? When I run it in the arcpy window, it is lightening quick. I've built a brand new MXD too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:07:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638059#M6938</guid>
      <dc:creator>RyanKelley</dc:creator>
      <dc:date>2021-12-12T03:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638060#M6939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Ryan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is something we are currently looking into.&amp;nbsp; We also have observed the performance issues concerning ListLayoutElements as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will see a difference between running this as a stand-alone script vs. running in the Python Window using CURRENT because the implementations are different.&amp;nbsp; Here is a very brief explanation: with CURRENT the code is acting directly on the map document in the application and all objects are directly accessible.&amp;nbsp; As a stand alone script, the code is acting against a map document that does not exist in an application but rather in a "fictitious" window that needs to be activated each time objects called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We hope to have this addressed for SP2.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Dec 2010 14:10:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638060#M6939</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2010-12-01T14:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638061#M6940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response Jeff.&amp;nbsp; It is interesting that in some MXDs this is not a problem, and others it is.&amp;nbsp; I thought my MXD was corrupt, so I started a new, very simple MXD. However, when I started adding a graticule, other text and legend elements, etc. I noticed that loop starting to get really slow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, SP2 sounds good... and I'll stop trying to trouble shoot this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Dec 2010 16:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638061#M6940</guid>
      <dc:creator>RyanKelley</dc:creator>
      <dc:date>2010-12-01T16:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638062#M6941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am encountering this issue with a python script (running from WING) with 10.0 SP3.&amp;nbsp; It must not have been resolved in SP2?&amp;nbsp; If I run the command in ArcMap, I find 264 layout elements (I am not quite sure how I have that many).&amp;nbsp; At any rate, I assume from Jeff's description that there are memory issues with creating that many instances of a virtual/fictional window?&amp;nbsp; Not sure how to work around this... any suggestions?&amp;nbsp; I am trying to query out elements whose names contain a partial string, and move them on the page, so I need the list that ListLayoutElements returns.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jan 2012 22:20:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638062#M6941</guid>
      <dc:creator>AprilBrough</dc:creator>
      <dc:date>2012-01-12T22:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638063#M6942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm fairly certain we addressed the memory issues discovered prior to SP2.&amp;nbsp; That does NOT mean you didn't find something else.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It sounds like you are surprised that there are so many elements in your MXD.&amp;nbsp; Have you tried saving it out to a new file?&amp;nbsp; Have you tried determining what the extra objects are and deleting them?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a trick that I use to minimize the number of times I call ListLayoutElements because every time you call it, it must iterate through all of your elements:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for elm in arcpy.mapping.ListLayoutElements(mxd):
&amp;nbsp; if elm.name == "title": title = elm
&amp;nbsp; if elm.name == "north arrow": northArrow = elm
&amp;nbsp; if elm.name == "graphic": graphic = elm
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code calls ListLayoutElements once vs 3 separate times like below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")[0]
northArrow = arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT", "north arrow")[0]
graphic = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "graphic")[0]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638063#M6942</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-12T03:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: ListLayoutElements for loop issue</title>
      <link>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638064#M6943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the quick response, Jeff.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Someone else prepared the mxd I am working with, which contains two legends and 12 scales bars that had been turned into graphics for detailed customization.&amp;nbsp; I realized that that there were many, many subgroups of the elements within the overall group elements I was trying to control.&amp;nbsp; This was done to assist with the manual relative alignment of the individual elements.&amp;nbsp; I ungrouped everything in the mxd, then recreated only the major element groups.&amp;nbsp; I also reworked the scale bar customization so I could use multiple dynamic bars instead of the graphic bars provided.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This reduced my total list of elements from 264 to 87, which increased the speed of my script.&amp;nbsp; Unfortunately, the script is still incredibly slow.&amp;nbsp; With the mxd I am currently running my script against (when I had 264 elements), ListLayoutElements ran for a couple hours and then my machine's resources were insufficient (I don't remember the exact message, but I believe it was caused by memory problems).&amp;nbsp; In the past, when running my script against a different mxd, this portion of the script was almost instantaneous.&amp;nbsp; The previous mxd had two legends and 12 scale bars as well, all of which contained grouped graphic elements.&amp;nbsp; I am not sure what the difference is between the mxds.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the tip about just creating the list of elements once, then subsequently filtering the desired elements.&amp;nbsp; That will greatly increase the speed of my script. Unfortunately, the ListLayoutElements is in multiple functions that I call for a series of projects (sometimes I run 200+ projects at once), so I will still be suffering quite a delay in total script runtime.&amp;nbsp; I could pass the list as an argument, but only within each project iteration, as each project generates its own mxd.&amp;nbsp; I will probably end up passing it between functions within a project, given how much time it would save.&amp;nbsp; It just seems more tedious that being able to create a quick list as needed within a function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will keep playing with this, and see if I determine any other differences between the mxds.&amp;nbsp; With ListLayoutElements as my only method of reaching a graphic legend or scale bar, I am not sure what my other options are for decreasing execution time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;~ April&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jan 2012 15:21:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/listlayoutelements-for-loop-issue/m-p/638064#M6943</guid>
      <dc:creator>AprilBrough</dc:creator>
      <dc:date>2012-01-13T15:21:06Z</dc:date>
    </item>
  </channel>
</rss>

