<?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 How to move a layer to a group? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1451864#M70566</link>
    <description>&lt;P&gt;Hi, I am trying to move a layer to a group using python. Both the layer and the group are in the current/same map.&lt;/P&gt;&lt;P&gt;I have the following code (the layer to be moved to the group "VMS" is "Fishnet_v1_manual")&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;mp = aprx.listMaps()[0]&lt;/P&gt;&lt;P&gt;lyr_to_move = mp.listLayers("Fishnet_v1_manual")&lt;BR /&gt;group_layer = mp.listLayers("VMS")&lt;/P&gt;&lt;P&gt;mp.addLayerToGroup(group_layer, lyr_to_move, "AUTO_ARRANGE")&lt;/P&gt;&lt;P&gt;But I keep getting this error:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;                                Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[37]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;8&lt;/SPAN&gt;:     mp.addLayerToGroup(group_layer, lyr_to_move, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;AUTO_ARRANGE&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;fn_&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;191&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; fn(*args, **kw)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;addLayerToGroup&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;3559&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;._arc_object.addLayerToGroup(*gp_fixargs((target_group_layer, add_layer_or_layerfile, add_position), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;: []&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried moving the layer to after the first layer in the group using moveLayer, but still get a similar error message as the above. The code I used for this is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;mp = aprx.listMaps()[0]&lt;/P&gt;&lt;P&gt;lyr_to_move = mp.listLayers("Fishnet_v1_FeatureLayer_v3")&lt;BR /&gt;ref_layer = mp.listLayers(r"Data points in grid")&lt;/P&gt;&lt;P&gt;mp.moveLayer(ref_layer, lyr_to_move, "AFTER")&lt;/P&gt;&lt;P&gt;The error message is:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;                                Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[38]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;9&lt;/SPAN&gt;:     mp.moveLayer(ref_layer, lyr_to_move, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;AFTER&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;fn_&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;191&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; fn(*args, **kw)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;moveLayer&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;3772&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;._arc_object.moveLayer(*gp_fixargs((reference_layer, move_layer, insert_position), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;: []&lt;/PRE&gt;&lt;P&gt;Any ideas on how to fix this error or are there other ways of moving a layer to a group in the current map? Thanks for your help and ideas.&lt;/P&gt;</description>
    <pubDate>Sun, 12 May 2024 21:17:56 GMT</pubDate>
    <dc:creator>HKN</dc:creator>
    <dc:date>2024-05-12T21:17:56Z</dc:date>
    <item>
      <title>How to move a layer to a group?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1451864#M70566</link>
      <description>&lt;P&gt;Hi, I am trying to move a layer to a group using python. Both the layer and the group are in the current/same map.&lt;/P&gt;&lt;P&gt;I have the following code (the layer to be moved to the group "VMS" is "Fishnet_v1_manual")&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;mp = aprx.listMaps()[0]&lt;/P&gt;&lt;P&gt;lyr_to_move = mp.listLayers("Fishnet_v1_manual")&lt;BR /&gt;group_layer = mp.listLayers("VMS")&lt;/P&gt;&lt;P&gt;mp.addLayerToGroup(group_layer, lyr_to_move, "AUTO_ARRANGE")&lt;/P&gt;&lt;P&gt;But I keep getting this error:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;                                Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[37]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;8&lt;/SPAN&gt;:     mp.addLayerToGroup(group_layer, lyr_to_move, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;AUTO_ARRANGE&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;fn_&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;191&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; fn(*args, **kw)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;addLayerToGroup&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;3559&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;._arc_object.addLayerToGroup(*gp_fixargs((target_group_layer, add_layer_or_layerfile, add_position), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;: []&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried moving the layer to after the first layer in the group using moveLayer, but still get a similar error message as the above. The code I used for this is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;mp = aprx.listMaps()[0]&lt;/P&gt;&lt;P&gt;lyr_to_move = mp.listLayers("Fishnet_v1_FeatureLayer_v3")&lt;BR /&gt;ref_layer = mp.listLayers(r"Data points in grid")&lt;/P&gt;&lt;P&gt;mp.moveLayer(ref_layer, lyr_to_move, "AFTER")&lt;/P&gt;&lt;P&gt;The error message is:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;                                Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[38]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;9&lt;/SPAN&gt;:     mp.moveLayer(ref_layer, lyr_to_move, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;AFTER&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;fn_&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;191&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; fn(*args, **kw)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;moveLayer&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;3772&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;._arc_object.moveLayer(*gp_fixargs((reference_layer, move_layer, insert_position), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;: []&lt;/PRE&gt;&lt;P&gt;Any ideas on how to fix this error or are there other ways of moving a layer to a group in the current map? Thanks for your help and ideas.&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2024 21:17:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1451864#M70566</guid>
      <dc:creator>HKN</dc:creator>
      <dc:date>2024-05-12T21:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a layer to a group?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1455166#M70567</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/471814"&gt;@HKN&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;listLayers always returns a list. When using the wildcard with a layer name or group layer name you are more than likely returning a list that contains one layer so you need to put [0] at the end like below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyr_to_move = mp.listLayers("Fishnet_v1_manual")[0]
group_layer = mp.listLayers("VMS")[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 06:09:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1455166#M70567</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-05-13T06:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a layer to a group?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1457528#M70573</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;, thanks for the above. It works fine now with this change.&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 12:34:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-move-a-layer-to-a-group/m-p/1457528#M70573</guid>
      <dc:creator>HKN</dc:creator>
      <dc:date>2024-05-13T12:34:04Z</dc:date>
    </item>
  </channel>
</rss>

