<?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: Legend not updated in exported layout (arcpy.mp exporting multiple maps) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1605257#M74026</link>
    <description>&lt;P&gt;In case anyone comes across this issue, I found a solution that worked for me. I'm currently using ArcGIS Pro 3.3.2 and running a python script in IDLE that exports a PDF of a layout after toggling a set of layers on and off.&lt;/P&gt;&lt;P&gt;Toggling the legend's syncLayerVisibility on and off before exporting the PDF (and after all the layer visibilities had been changed) worked to refresh the legend:&lt;/P&gt;&lt;P&gt;pLegend = pLayout.listElements("LEGEND_ELEMENT","Legend")[0]&lt;/P&gt;&lt;P&gt;pLegend.syncLayerVisibility = False&lt;BR /&gt;pLegend.syncLayerVisibility = True&lt;/P&gt;</description>
    <pubDate>Fri, 11 Apr 2025 16:15:44 GMT</pubDate>
    <dc:creator>DrewSparks</dc:creator>
    <dc:date>2025-04-11T16:15:44Z</dc:date>
    <item>
      <title>Legend not updated in exported layout (arcpy.mp exporting multiple maps)</title>
      <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/374638#M29604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using arcpy.mp to export multiple layers at once, but having a trouble that legend is not updated.&lt;/P&gt;&lt;P&gt;Each layer is successfully exported as separate JPEG file by the code below.&amp;nbsp;However, the legend attached to each exported output is all the same (legend of the first layer).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I usually run my script as standalone from Jupyter notebook. When I run the code below in python window within ArcGIS pro, legend was successfully updated in each exported output.&lt;/P&gt;&lt;P&gt;If anybody has any idea on why it cannot be done by standalone, I would really appreciate it.&lt;/P&gt;&lt;P&gt;ArcGIS Pro 2.2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#&lt;EM&gt;&amp;nbsp;This is the code I ran&lt;/EM&gt;&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject(r"C:\Users\kenta\Documents\ArcGIS\Projects\CoHRE_Collaboration\CoHRE_Collaboration.aprx")&lt;BR /&gt;maps = aprx.listMaps("Oki")[0]&lt;BR /&gt;layers = maps.listLayers("mean*")&lt;BR /&gt;layout = aprx.listLayouts("Oki_layout")[0]&lt;/P&gt;&lt;P&gt;for layer in layers:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;layer.visible=False&lt;BR /&gt;for layer in layers:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;layer.visible = True&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;layout.exportToJPEG(r"C:\Users\kenta\Dropbox\Collaboration\CollaborationOki"+ "\\" + layer.name + ".JPEG")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;layer.visible = False&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2018 06:19:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/374638#M29604</guid>
      <dc:creator>KentaOkuyama</dc:creator>
      <dc:date>2018-11-09T06:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Legend not updated in exported layout (arcpy.mp exporting multiple maps)</title>
      <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1029869#M60081</link>
      <description>&lt;P&gt;Hi Kenta,&lt;/P&gt;&lt;P&gt;I know this is old but did you ever resolve this issue?&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 02:37:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1029869#M60081</guid>
      <dc:creator>DavidMatthews3</dc:creator>
      <dc:date>2021-02-24T02:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Legend not updated in exported layout (arcpy.mp exporting multiple maps)</title>
      <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1199117#M65185</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I saw a couple of posts about this topic but no solution. My code makes a set of layers visible, one at a time, and exports a layout with each layer visible. I found that if I toggle the legend visibility as well, that I can get the legend to update as expected in the exported layout. To do this, I pulled the legend element (in my case, I have only one legend) from my layout object, changed the visible property to True, completed some other operations, then changed the legend visibility back to False.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Hope this helps someone. Code below.&lt;BR /&gt;Sydney&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Iterate through layer objects.
for lyr in layers_to_export:
    # Make desired layer visible and make the legend visible.
    lyr.visible = True
    legend = layout.listElements("LEGEND_ELEMENT")[0]
    legend.visible = True
    
    if title_bool:
        # Change title text
        title = layout.listElements("TEXT_ELEMENT", title_element_name)[0]
        title.text = title_start + lyr.name

    # Export layout to PDF
    layout.exportToPDF(os.path.join(output_dir, f"{lyr.name}.pdf"))

    # Make layer invisible again, toggle legend off
    lyr.visible = False
    legend.visible = False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 19:22:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1199117#M65185</guid>
      <dc:creator>SydneyWagner</dc:creator>
      <dc:date>2022-08-03T19:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Legend not updated in exported layout (arcpy.mp exporting multiple maps)</title>
      <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1340645#M69019</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was having this issue with a for loop to export a series of maps. Your response with toggling legend visibility fixed my problem. Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 19:27:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1340645#M69019</guid>
      <dc:creator>Mya_Yazbek</dc:creator>
      <dc:date>2023-10-23T19:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Legend not updated in exported layout (arcpy.mp exporting multiple maps)</title>
      <link>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1605257#M74026</link>
      <description>&lt;P&gt;In case anyone comes across this issue, I found a solution that worked for me. I'm currently using ArcGIS Pro 3.3.2 and running a python script in IDLE that exports a PDF of a layout after toggling a set of layers on and off.&lt;/P&gt;&lt;P&gt;Toggling the legend's syncLayerVisibility on and off before exporting the PDF (and after all the layer visibilities had been changed) worked to refresh the legend:&lt;/P&gt;&lt;P&gt;pLegend = pLayout.listElements("LEGEND_ELEMENT","Legend")[0]&lt;/P&gt;&lt;P&gt;pLegend.syncLayerVisibility = False&lt;BR /&gt;pLegend.syncLayerVisibility = True&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 16:15:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/legend-not-updated-in-exported-layout-arcpy-mp/m-p/1605257#M74026</guid>
      <dc:creator>DrewSparks</dc:creator>
      <dc:date>2025-04-11T16:15:44Z</dc:date>
    </item>
  </channel>
</rss>

