<?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 Moving a layer to a SUB-group in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/moving-a-layer-to-a-sub-group/m-p/1545150#M72981</link>
    <description>&lt;P&gt;Can anyone post the code to move a layer to a SUB-group-layer?&lt;/P&gt;&lt;P&gt;The following code (courtesy of&amp;nbsp;&lt;A href="https://gis.stackexchange.com/questions/475584/move-an-existing-layer-into-a-group-layer-using-arcpy-in-arcgis-pro" target="_blank" rel="noopener"&gt;https://gis.stackexchange.com/questions/475584/move-an-existing-layer-into-a-group-layer-using-arcpy-in-arcgis-pro&lt;/A&gt;) works fine for copying the layer to a top-level group-layer, but I can't get it working for a group layer within another group layer e.g. MyGroupLayer/SubGroupA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;lyr_to_move = mp.listLayers(&lt;SPAN class=""&gt;"My Layer Name"&lt;/SPAN&gt;)[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]
group_layer = mp.listLayers(&lt;SPAN class=""&gt;"MyGroupLayer"&lt;/SPAN&gt;)[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]

&lt;SPAN class=""&gt;# Use this to move layers (but not into a group layer)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;#mp.moveLayer(group_layer, lyr_to_move, "AFTER")&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Use this to move a layer into a group layer&lt;/SPAN&gt;
mp.addLayerToGroup(group_layer, lyr_to_move, &lt;SPAN class=""&gt;"AUTO_ARRANGE"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2024 13:00:04 GMT</pubDate>
    <dc:creator>Shane_EU</dc:creator>
    <dc:date>2024-10-03T13:00:04Z</dc:date>
    <item>
      <title>Moving a layer to a SUB-group</title>
      <link>https://community.esri.com/t5/python-questions/moving-a-layer-to-a-sub-group/m-p/1545150#M72981</link>
      <description>&lt;P&gt;Can anyone post the code to move a layer to a SUB-group-layer?&lt;/P&gt;&lt;P&gt;The following code (courtesy of&amp;nbsp;&lt;A href="https://gis.stackexchange.com/questions/475584/move-an-existing-layer-into-a-group-layer-using-arcpy-in-arcgis-pro" target="_blank" rel="noopener"&gt;https://gis.stackexchange.com/questions/475584/move-an-existing-layer-into-a-group-layer-using-arcpy-in-arcgis-pro&lt;/A&gt;) works fine for copying the layer to a top-level group-layer, but I can't get it working for a group layer within another group layer e.g. MyGroupLayer/SubGroupA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;lyr_to_move = mp.listLayers(&lt;SPAN class=""&gt;"My Layer Name"&lt;/SPAN&gt;)[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]
group_layer = mp.listLayers(&lt;SPAN class=""&gt;"MyGroupLayer"&lt;/SPAN&gt;)[&lt;SPAN class=""&gt;0&lt;/SPAN&gt;]

&lt;SPAN class=""&gt;# Use this to move layers (but not into a group layer)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;#mp.moveLayer(group_layer, lyr_to_move, "AFTER")&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Use this to move a layer into a group layer&lt;/SPAN&gt;
mp.addLayerToGroup(group_layer, lyr_to_move, &lt;SPAN class=""&gt;"AUTO_ARRANGE"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 13:00:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-a-layer-to-a-sub-group/m-p/1545150#M72981</guid>
      <dc:creator>Shane_EU</dc:creator>
      <dc:date>2024-10-03T13:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Moving a layer to a SUB-group</title>
      <link>https://community.esri.com/t5/python-questions/moving-a-layer-to-a-sub-group/m-p/1545166#M72985</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/781468"&gt;@Shane_EU&lt;/a&gt;,&amp;nbsp;the following should work:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.listMaps("Map")[0]

lyr_to_move = mp.listLayers("Airports")[0]
group_layer = mp.listLayers("SubGroup")[0]

# Use this to move a layer into a group layer
mp.addLayerToGroup(group_layer, lyr_to_move, "AUTO_ARRANGE")

# Remove layer from map
mp.removeLayer(lyr_to_move)&lt;/LI-CODE&gt;
&lt;P&gt;Before script:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1727961755364.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/116418i31633727D500E263/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1727961755364.png" alt="JakeSkinner_0-1727961755364.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;After script:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_1-1727961779266.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/116419i04B09C729C6F3CAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_1-1727961779266.png" alt="JakeSkinner_1-1727961779266.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 13:23:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/moving-a-layer-to-a-sub-group/m-p/1545166#M72985</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-10-03T13:23:48Z</dc:date>
    </item>
  </channel>
</rss>

