<?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: Making Layers invisible via ArcPy 3+ in ArcGIS Pro 3+ in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1313032#M68274</link>
    <description>&lt;P&gt;Not sure where you are running the code or what your layer name is, but you do this through the mapping module.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(r'path to aprx') # Use 'current' if executing in Pro Python window.

m = aprx.listMaps("Map")[0]

lyrName = 'layer_name'
lyr = m.listLayers(lyrName)[0]
lyr.visible = False
arcpy.AddMessage(f"Set layer-visibility for {lyr.name} to str(lyr.visible)")

# aprx.save() &amp;lt;- might need this if ran from outside of Pro's env, but the aprx will need to be closed or you will get an error.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 12:30:21 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-07-28T12:30:21Z</dc:date>
    <item>
      <title>Making Layers invisible via ArcPy 3+ in ArcGIS Pro 3+</title>
      <link>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1312994#M68273</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am trying to change the visibility of some layers via an ArcPy script.&lt;/P&gt;&lt;P&gt;It seems like the property &lt;FONT face="courier new,courier"&gt;visible&lt;/FONT&gt; of the layer object is the property to go. I found multiple articles on how it works in ArcMap, for example this one: &lt;A href="https://support.esri.com/en-us/knowledge-base/how-to-toggle-the-visibility-of-a-specific-sublayer-of-000013577" target="_blank" rel="noopener"&gt;https://support.esri.com/en-us/knowledge-base/how-to-toggle-the-visibility-of-a-specific-sublayer-of-000013577&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Within ArcGIS Pro 3+ and with ArcPy 3+, I am able to set the property to either &lt;FONT face="courier new,courier"&gt;True&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;False&lt;/FONT&gt; for a layer without problems.&lt;/P&gt;&lt;P&gt;However, it seems like you actually need to somehow refresh the view in order to have some visual effect on the map rendering and also in the Contents pane.&lt;/P&gt;&lt;P&gt;For older versions of ArcPy/with ArcMap, it seems like calling the following two methods was sufficient:&lt;/P&gt;&lt;PRE&gt;arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;P&gt;However, when I call these methods now on arcpy, I receive an error: "&lt;FONT color="#FF0000"&gt;AttributeError: module 'arcpy' has not attribute 'RefreshTOC'&lt;/FONT&gt;".&amp;nbsp; Hence, it seems like these two methods do no longer exist in ArcPy 3+.&lt;/P&gt;&lt;P&gt;Does anybody have an idea how I can change the visibility of a layer such that it actually also is displayed accordingly in the map rendering and in the Contents pane?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 09:34:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1312994#M68273</guid>
      <dc:creator>lbd_bayern</dc:creator>
      <dc:date>2023-07-28T09:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Making Layers invisible via ArcPy 3+ in ArcGIS Pro 3+</title>
      <link>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1313032#M68274</link>
      <description>&lt;P&gt;Not sure where you are running the code or what your layer name is, but you do this through the mapping module.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(r'path to aprx') # Use 'current' if executing in Pro Python window.

m = aprx.listMaps("Map")[0]

lyrName = 'layer_name'
lyr = m.listLayers(lyrName)[0]
lyr.visible = False
arcpy.AddMessage(f"Set layer-visibility for {lyr.name} to str(lyr.visible)")

# aprx.save() &amp;lt;- might need this if ran from outside of Pro's env, but the aprx will need to be closed or you will get an error.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 12:30:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1313032#M68274</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-07-28T12:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Making Layers invisible via ArcPy 3+ in ArcGIS Pro 3+</title>
      <link>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1313513#M68293</link>
      <description>&lt;P&gt;Hi @Anonymous User,&lt;/P&gt;&lt;P&gt;I executed the script in the ArcGIS Pro Python window and was actually getting the reference to the aprx via path. After changing it to&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;/LI-CODE&gt;&lt;P&gt;it now works as expected.&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 07:04:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/making-layers-invisible-via-arcpy-3-in-arcgis-pro/m-p/1313513#M68293</guid>
      <dc:creator>lbd_bayern</dc:creator>
      <dc:date>2023-07-31T07:04:29Z</dc:date>
    </item>
  </channel>
</rss>

