<?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: UpdateLayer Not Showing Changes in TOC or ActiveView in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319773#M24852</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much for your response.&amp;nbsp; I should have realize that I need to list the layers in the map, not the Feature Classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I've modified my code as follows, but it crashes on line 33 ("&amp;nbsp; BasinLayer = arcpy.mapping.Layer(Basin)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea why?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import arcpy.mapping
import datetime
import os


arcpy.env.overwriteOutput = True
GeoDatabaseNameAndLocation = "G:\MaxtorDrive\GroundwaterDatabases\GWIDS\GroundwaterBasinOverdraftAnalysis.gdb"


GeoDatabaseName = os.path.basename(GeoDatabaseNameAndLocation)
GeoDatabaseLocation = os.path.dirname(GeoDatabaseNameAndLocation)

##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

arcpy.env.workspace = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins")
CurrentWorkspacePath = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins")
PORSymbologyLayer = arcpy.mapping.Layer(os.path.join(GeoDatabaseLocation,"GIS","PeriodOfRecord.lyr"))
arcpy.AddMessage(PORSymbologyLayer)
BasinList = arcpy.ListFeatureClasses("*")
arcpy.AddMessage(BasinList)
for Basin in BasinList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BasinFeatureClass = arcpy.mapping.Layer(Basin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(BasinFeatureClass)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, BasinFeatureClass, "TOP")

#Create list of Basin Layer in map.
BasinLayersInMap = arcpy.mapping.ListLayers(mxd,"*",df)
arcpy.AddMessage(BasinLayersInMap)
for Basin in BasinLayersInMap:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BasinLayer = arcpy.mapping.Layer(Basin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df,BasinLayer,PORSymbologyLayer,"TRUE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:11:46 GMT</pubDate>
    <dc:creator>JonathanMulder</dc:creator>
    <dc:date>2021-12-11T15:11:46Z</dc:date>
    <item>
      <title>UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319771#M24850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've been wrestling with this for most of the day and am flummoxed!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am going through a "For Loop" adding 5 (ultimately will be ~150 after testing) feature classes in a Feature Dataset (named "GroundwaterBasins") in a geodatabase, and trying to change the symbology for each dataset based upon a layer file that I have already saved ("PORSymbologyLayer").&amp;nbsp; I have inserted "arcpy.RefreshTOC" and "arcpy.RefreshActiveView".&amp;nbsp; I've even broken it down into two "For Loops (one for adding the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;feature class, and one for changing the symbology).&amp;nbsp; I've even tried "ApplySymbologyFromLayer_mangement" which also doesn't change the symbology.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anyone see what I'm doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jonathan Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Engineering Geologist&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California Department of Water Resources&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Reference the Current map document. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0]&amp;nbsp; arcpy.env.workspace = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins") CurrentWorkspacePath = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins") PORSymbologyLayer = arcpy.mapping.Layer(os.path.join(GeoDatabaseLocation,"GIS","PeriodOfRecord.lyr")) arcpy.AddMessage(PORSymbologyLayer) BasinList = arcpy.ListFeatureClasses("*") arcpy.AddMessage(BasinList) for Basin in BasinList: &amp;nbsp;&amp;nbsp;&amp;nbsp; BasinFeatureClass = arcpy.mapping.Layer(Basin) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(BasinFeatureClass) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, BasinFeatureClass, "TOP") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&amp;nbsp; for Basin in BasinList: &amp;nbsp;&amp;nbsp;&amp;nbsp; BasinFeatureClass = arcpy.mapping.Layer(Basin) ##&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management (BasinFeatureClass, PORSymbologyLayer) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df,BasinFeatureClass,PORSymbologyLayer) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jun 2014 17:02:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319771#M24850</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2014-06-05T17:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319772#M24851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It looks like when you go to update the symbolization&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(I hate that awful word: "symbology". ugh. It is neither a science nor a religion... anyway...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you are not operating on the ArcMap layers you just added.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead, you are again looping through BasinList&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BasinList is a list of feature classes on disk&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;even though you again make layers from the FCs, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;they are NOT the layers in your ArcMap data frame.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For your symbolization loop, start with a new list of layers in the data frame,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;using: ListLayers (map_document_or_layer, {wildcard}, {data_frame})&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This list will contain the objects you need to update.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, when you do the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.UpdateLayer(df,BasinFeatureClass,PORSymbologyLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;make it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.UpdateLayer(df,BasinFeatureClass,PORSymbologyLayer, True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, the default is True, but, as it says in the Zen of Python (&amp;gt;&amp;gt;&amp;gt; import this):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Explicit is better than implicit.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 12:05:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319772#M24851</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-06-06T12:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319773#M24852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much for your response.&amp;nbsp; I should have realize that I need to list the layers in the map, not the Feature Classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I've modified my code as follows, but it crashes on line 33 ("&amp;nbsp; BasinLayer = arcpy.mapping.Layer(Basin)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea why?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import arcpy.mapping
import datetime
import os


arcpy.env.overwriteOutput = True
GeoDatabaseNameAndLocation = "G:\MaxtorDrive\GroundwaterDatabases\GWIDS\GroundwaterBasinOverdraftAnalysis.gdb"


GeoDatabaseName = os.path.basename(GeoDatabaseNameAndLocation)
GeoDatabaseLocation = os.path.dirname(GeoDatabaseNameAndLocation)

##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

arcpy.env.workspace = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins")
CurrentWorkspacePath = os.path.join(GeoDatabaseNameAndLocation,"GroundwaterBasins")
PORSymbologyLayer = arcpy.mapping.Layer(os.path.join(GeoDatabaseLocation,"GIS","PeriodOfRecord.lyr"))
arcpy.AddMessage(PORSymbologyLayer)
BasinList = arcpy.ListFeatureClasses("*")
arcpy.AddMessage(BasinList)
for Basin in BasinList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BasinFeatureClass = arcpy.mapping.Layer(Basin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(BasinFeatureClass)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, BasinFeatureClass, "TOP")

#Create list of Basin Layer in map.
BasinLayersInMap = arcpy.mapping.ListLayers(mxd,"*",df)
arcpy.AddMessage(BasinLayersInMap)
for Basin in BasinLayersInMap:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BasinLayer = arcpy.mapping.Layer(Basin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df,BasinLayer,PORSymbologyLayer,"TRUE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:11:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319773#M24852</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2021-12-11T15:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319774#M24853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Jon-&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's because ListLayers returns a list of Layer objects, so you don't need to try to 'reinstantiate' it as that kind of object - you should be able to do this (provided there's actually a return from ListLayers):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;BasinLayersInMap = arcpy.mapping.ListLayers(mxd,"*",df) arcpy.AddMessage(BasinLayersInMap) for Basin in BasinLayersInMap: &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df, Basin, PORSymbologyLayer,"TRUE") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 15:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319774#M24853</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-06-06T15:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319775#M24854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That did the trick, Wayne!&amp;nbsp; Thanks very much!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 15:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319775#M24854</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2014-06-06T15:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateLayer Not Showing Changes in TOC or ActiveView</title>
      <link>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319776#M24855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jon, since you said you'll be executing this on quite a few more layers (150+ ?), I'd like to suggest 'combining' your for loops into this one (I didn't test this) in the interest of efficiency (if it works):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for Basin in BasinList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; BasinFeatureClass = arcpy.mapping.Layer(Basin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(BasinFeatureClass)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df,BasinFeatureClass,PORSymbologyLayer,"TRUE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, BasinFeatureClass, "TOP")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if UpdateLayer output is auto-added to the map; if so, you don't need AddLayer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, if you'd like to award Mark something for his contribution, he probably deserves it -- I just came in on this at the tail end...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS- Agreed, Mark, ha ha:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"Yes, the default is True, but, as it says in the Zen of Python (&amp;gt;&amp;gt;&amp;gt; import this):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Explicit is better than implicit."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For anyone who hasn't seen the printout of Zen of Python, enter &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;import this&lt;/SPAN&gt;&lt;SPAN&gt; at the python command prompt.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatelayer-not-showing-changes-in-toc-or/m-p/319776#M24855</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T15:11:49Z</dc:date>
    </item>
  </channel>
</rss>

