<?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: [bug?]Layers with the same name are not distinguished in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1513066#M71169</link>
    <description>&lt;P&gt;Maybe specify the group layer name?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Define the path to the project and the map
aprx_path = r'C:\path\project.aprx'
map_name = 'Map'
group_layer_to_turn_on = 'YourGroupLayerName'  # Specify the name of the group layer

# Open the project
aprx = arcpy.mp.ArcGISProject(aprx_path)

# Get the map
m = aprx.listMaps(map_name)[0]

# Function to turn on a specific group layer and its sub-layers recursively
def turn_on_specific_group_layer(layer, group_layer_name):
    if layer.isGroupLayer and layer.name == group_layer_name:
        layer.visible = True
        print(f"Turned on visibility for group layer: {layer.name}")
        for sub_layer in layer.listLayers():
            turn_on_sub_layers(sub_layer)  # Recursively check sub-layers

# Function to turn on all sub-layers of a specific group layer
def turn_on_sub_layers(layer):
    if layer.isGroupLayer:
        layer.visible = True
        print(f"Turned on visibility for sub-group layer: {layer.name}")
        for sub_layer in layer.listLayers():
            turn_on_sub_layers(sub_layer)  # Recursively check sub-layers
    else:
        layer.visible = True
        print(f"Turned on visibility for sub-layer: {layer.name}")

# Loop through top-level layers in the map to find the specific group layer
for lyr in m.listLayers():
    turn_on_specific_group_layer(lyr, group_layer_to_turn_on)

# Save the project
#aprx.save()
#print("Project saved.")

# Clean up
#del aprx&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 31 Jul 2024 17:27:40 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2024-07-31T17:27:40Z</dc:date>
    <item>
      <title>[bug?]Layers with the same name are not distinguished</title>
      <link>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1511320#M71146</link>
      <description>&lt;P&gt;I created a code that gets multiple layers from the parameters and makes them visible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

selectLayerLists=arcpy.GetParameterAsText(0) #LayerList

aprx=arcpy.mp.ArcGISProject("CURRENT") 
lay=aprx.activeView #Layout 
mf=lay.listElements("mapframe_element","*")[0] 
map=mf.map 
Lyr_list=selectLayerLists.split(";") 
arcpy.AddMessage(Lyr_list) 

for lyr in Lyr_list:
    map.listLayers(lyr)[0].visible=True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Layer structure:&lt;BR /&gt;ryoho&lt;BR /&gt;ryoho/L02&lt;BR /&gt;ryoho/L01&lt;BR /&gt;L02&lt;BR /&gt;L01&lt;/P&gt;&lt;P&gt;The layer selected as the parameter:&lt;BR /&gt;ryoho&lt;BR /&gt;L02&lt;BR /&gt;L01&lt;/P&gt;&lt;P&gt;Code execution results:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="タイトルなし.png" style="width: 198px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110893i8DE34D818B59D254/image-size/small?v=v2&amp;amp;px=200" role="button" title="タイトルなし.png" alt="タイトルなし.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As shown in the image, the group layer and layers with the same name within the group have been switched to display.&lt;BR /&gt;How can you get the results you want with the parameters?&lt;/P&gt;&lt;P&gt;As an experiment, I retrieved the parameters with "GetParameter" and set the retrieved layer.visible=True, but the layer did not appear.&lt;BR /&gt;In 3.2.2, layers with the same name were distinguished as "Layer1:1" and "Layer1:2", so this code worked without any problems, but after updating to 3.3.1, the following situation occurred.&lt;/P&gt;&lt;P&gt;Due to the nature of my work, there are many layers with the same name, and changing the layer names for the sake of creating legends is not a good idea.&lt;BR /&gt;I would appreciate any ideas on how to solve this problem.&lt;BR /&gt;I would also like to know if this problem is only occurring in my environment.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 05:42:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1511320#M71146</guid>
      <dc:creator>-_-</dc:creator>
      <dc:date>2024-07-29T05:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: [bug?]Layers with the same name are not distinguished</title>
      <link>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1513066#M71169</link>
      <description>&lt;P&gt;Maybe specify the group layer name?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Define the path to the project and the map
aprx_path = r'C:\path\project.aprx'
map_name = 'Map'
group_layer_to_turn_on = 'YourGroupLayerName'  # Specify the name of the group layer

# Open the project
aprx = arcpy.mp.ArcGISProject(aprx_path)

# Get the map
m = aprx.listMaps(map_name)[0]

# Function to turn on a specific group layer and its sub-layers recursively
def turn_on_specific_group_layer(layer, group_layer_name):
    if layer.isGroupLayer and layer.name == group_layer_name:
        layer.visible = True
        print(f"Turned on visibility for group layer: {layer.name}")
        for sub_layer in layer.listLayers():
            turn_on_sub_layers(sub_layer)  # Recursively check sub-layers

# Function to turn on all sub-layers of a specific group layer
def turn_on_sub_layers(layer):
    if layer.isGroupLayer:
        layer.visible = True
        print(f"Turned on visibility for sub-group layer: {layer.name}")
        for sub_layer in layer.listLayers():
            turn_on_sub_layers(sub_layer)  # Recursively check sub-layers
    else:
        layer.visible = True
        print(f"Turned on visibility for sub-layer: {layer.name}")

# Loop through top-level layers in the map to find the specific group layer
for lyr in m.listLayers():
    turn_on_specific_group_layer(lyr, group_layer_to_turn_on)

# Save the project
#aprx.save()
#print("Project saved.")

# Clean up
#del aprx&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 31 Jul 2024 17:27:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1513066#M71169</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-07-31T17:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: [bug?]Layers with the same name are not distinguished</title>
      <link>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1513591#M71175</link>
      <description>&lt;P&gt;Give&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm#:~:text=Boolean-,longName,-(Read%20Only)" target="_blank" rel="noopener"&gt;longName&lt;/A&gt;&amp;nbsp;a shot, that will include if it's in a group layer or not. You'll probably just have to do it as a check of some sort, like&lt;/P&gt;&lt;PRE&gt;"if '\\'in lay.longName"&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2024 13:35:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1513591#M71175</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-08-01T13:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: [bug?]Layers with the same name are not distinguished</title>
      <link>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1517111#M71230</link>
      <description>&lt;P&gt;Thank you for the idea.&lt;/P&gt;&lt;P&gt;However, since I need to get the layer name as a parameter, it's a pain to specify the group name each time.&lt;/P&gt;&lt;P&gt;So I decided to temporarily process it using the index number until it returns to normal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

selectLayerLists=arcpy.GetParameterAsText(0) #レイヤリスト

aprx=arcpy.mp.ArcGISProject("CURRENT")

lay=aprx.activeView

mf=lay.listElements("mapframe_element","*")[0]

map=mf.map

allLayerList=map.listLayers()
allLayerList_index=[]

Lyr_list=selectLayerLists.split(";") #レイヤ名をリストに分割


for i in range(0,len(allLayerList)):
    allLayerList_index.append([i,map.listLayers()[i].longName])

arcpy.AddMessage(allLayerList_index)

for n in range(0,len(allLayerList_index)):
    arcpy.AddMessage(allLayerList_index[n][1])
    if allLayerList_index[n][1] in Lyr_list:
        targetNumber=allLayerList_index[n][0]
        map.listLayers()[targetNumber].visible=False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 02:24:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-layers-with-the-same-name-are-not/m-p/1517111#M71230</guid>
      <dc:creator>-_-</dc:creator>
      <dc:date>2024-08-09T02:24:12Z</dc:date>
    </item>
  </channel>
</rss>

