<?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: Improve my script so it toggle on/off layers after updating them in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566871#M44391</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm maybe the mxd needs a refresh &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/page-layouts/refreshing-data-driven-pages.htm" title="http://desktop.arcgis.com/en/arcmap/latest/map/page-layouts/refreshing-data-driven-pages.htm"&gt;Refreshing Data Driven Pages—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;thinkin example 2 here &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument.htm"&gt;MapDocument—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;refreshtoc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Apr 2016 21:53:02 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-04-14T21:53:02Z</dc:date>
    <item>
      <title>Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566867#M44387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;The following script works perfectly to update all mxds contained in one folder using a unique .lyr file as a reference to all layers (in groups and subgroups). All mxds have the same TOC composition, but the visibility of each layer depend of the mxd. My problem is that when I run the "update script", the .lyr file apply his parameter to the layers so it turns them OFF. The .lyr file contains only OFF layers because, as I said, the visibility of every layer is different in each map project.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I would love to find a way to integrate a few more lines of code in the script so it would list the layers visibility parameter (for every layers in the mxd), then do the update, finally toggle back ON the layers that were ON initially using the list. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found something, but I can't find a way to integrate it in the "update script" (&lt;A href="http://gis.stackexchange.com/a/158476/69986" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gis.stackexchange.com/a/158476/69986&lt;/A&gt;​). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the "update script": &lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
import os


MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
&amp;nbsp;&amp;nbsp;&amp;nbsp; MxdFolderPath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Mise_a_jour/Test"
MxdCount = 0


sourcelypath = arcpy.GetParameterAsText(1)
if sourcelypath == '#' or not sourcelypath:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sourcelypath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Fichiers .lyr/Autres formats/Couches.lyr"&amp;nbsp; # reference .lyr file
sourcely = arcpy.mapping.Layer(sourcelypath)


arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage("&amp;nbsp;&amp;nbsp; MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("&amp;nbsp;&amp;nbsp; There are no mxd in: " + str(MxdFolderPath))
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("&amp;nbsp;&amp;nbsp; There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))


&amp;nbsp;&amp;nbsp;&amp;nbsp; for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MxdCount = (MxdCount + 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MxdPPath = os.path.join(MxdFolderPath, mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; processingmxd = arcpy.mapping.MapDocument(MxdPPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(" Mxd: " + str(MxdCount) + " :" + str(mxd))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dflist = arcpy.mapping.ListDataFrames(processingmxd, "Couches_DF")&amp;nbsp; # Dataframe
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in dflist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(" df: " + str(df.name))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layers = arcpy.mapping.ListLayers(processingmxd, "Couches", df)&amp;nbsp; # layers called Couches
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Layer: " + str(layer))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df, layer, sourcely, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Layer Updated")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; processingmxd.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(" ")
arcpy.AddMessage(" End")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help? Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:25:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566867#M44387</guid>
      <dc:creator>AntoineCantin</dc:creator>
      <dc:date>2021-12-12T00:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566868#M44388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;I think you should be able to do something like the following inside your loop:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;orig_vis = layer.visible # either True or False&lt;/SPAN&gt;
&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;arcpy.mapping.UpdateLayer(df, layer, sourcely, &lt;/SPAN&gt;&lt;SPAN class="special" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;False&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;) # update layer&lt;/SPAN&gt;
&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;layer.visible = orig_vis # set visibility&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566868#M44388</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T00:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566869#M44389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Darren is correct since layer.visible is a read and write property &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm"&gt;Layer—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;As a matter of reference... bookmark this link for the whole of arcpy &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy/what-is-arcpy-.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy/what-is-arcpy-.htm"&gt;What is ArcPy?—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:00:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566869#M44389</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-14T21:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566870#M44390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Gave it a try, but it didn't work... The good side: there's is no error message.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:51:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566870#M44390</guid>
      <dc:creator>AntoineCantin</dc:creator>
      <dc:date>2016-04-14T21:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566871#M44391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm maybe the mxd needs a refresh &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/page-layouts/refreshing-data-driven-pages.htm" title="http://desktop.arcgis.com/en/arcmap/latest/map/page-layouts/refreshing-data-driven-pages.htm"&gt;Refreshing Data Driven Pages—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;thinkin example 2 here &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument.htm"&gt;MapDocument—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;refreshtoc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:53:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566871#M44391</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-14T21:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566872#M44392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What version of ArcGIS for Desktop are you working with?&amp;nbsp; Just a theory that this might have something to do with the layer.visible property not working as expected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566872#M44392</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2016-04-14T22:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566873#M44393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have to refresh if the mxd's aren't open?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:10:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566873#M44393</guid>
      <dc:creator>AntoineCantin</dc:creator>
      <dc:date>2016-04-14T22:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566874#M44394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is 10.3.1 (basic license)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:10:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566874#M44394</guid>
      <dc:creator>AntoineCantin</dc:creator>
      <dc:date>2016-04-14T22:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566875#M44395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about having 2 different lyr files, 1 with the layer visible and the other with the layer not visible.&amp;nbsp; Then when you check the current visibility of the layer in the mxd this determines which lyr file to use.&amp;nbsp; This could alleviate the current problem you are having if the map cannot be refreshed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566875#M44395</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2016-04-14T22:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Improve my script so it toggle on/off layers after updating them</title>
      <link>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566876#M44396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think the current problem is to refresh, the script loops through a folder to apply it to every mxd. But your idea isn't bad, I would have to create a .lyr for each mxd then add some lines to the script to use this new .lyr only to set visibility... Now I have to find how to do it! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:53:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/improve-my-script-so-it-toggle-on-off-layers-after/m-p/566876#M44396</guid>
      <dc:creator>AntoineCantin</dc:creator>
      <dc:date>2016-04-14T22:53:32Z</dc:date>
    </item>
  </channel>
</rss>

