<?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: ArcGIS Pro: map.MoveLayer not working as expected in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1326276#M68541</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;thanks for your reply, and good to know that this restriction is explicitly stated in the documentation. I was able to solve my problem with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class=""&gt;addLayerToGroup&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;()&lt;/FONT&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2023 08:42:28 GMT</pubDate>
    <dc:creator>lbd_bayern</dc:creator>
    <dc:date>2023-09-07T08:42:28Z</dc:date>
    <item>
      <title>ArcGIS Pro: map.MoveLayer not working as expected</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1324658#M68510</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;I am trying to move a Group Layer (A) next to another Group Layer (B). B is the child of a third Group Layer (C). When I try to move the A next to B with the method &lt;FONT face="courier new,courier"&gt;map.MoveLayer&lt;/FONT&gt;, A is not placed on the same hierarchy level as B but on the same hierarchy level as C.&lt;/P&gt;&lt;P&gt;Intended result:&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;&lt;P&gt;∟ B&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;∟&lt;/STRONG&gt;&amp;nbsp;A&lt;/P&gt;&lt;P&gt;Actual result:&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;&lt;P&gt;∟ B&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To make this more concrete, please see my example code starting from an empty map. In the code, the respective Group Layers correspond to the following variable names:&lt;/P&gt;&lt;P&gt;A = &lt;FONT face="courier new,courier"&gt;group_layer_to_move_next_to_child_layer&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;B = &lt;FONT face="courier new,courier"&gt;child_group_layer&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;C = &lt;FONT face="courier new,courier"&gt;parent_group_layer&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;##### SCRIPT VARIABLES TO ADJUST #####
PATH_LYRX_FILE = r'C:\Projects\ArcGISPro\Test_GroupLayer_below_GroupLayer6\all.lyrx'  # TODO: adjust to your project

##### ACTUAL SCRIPT #####
current_project = arcpy.mp.ArcGISProject("CURRENT")
map = current_project.activeMap
lyrx_file = arcpy.mp.LayerFile(PATH_LYRX_FILE)

# add parent_group_layer to the map
parent_group_layer = map.addLayer(lyrx_file)[0]
parent_group_layer.name = 'Parent_Group_Layer'

# add child_group_layer to the map ... 
child_group_layer = map.addLayer(lyrx_file)[0]
child_group_layer.name = 'Child_Group_Layer'
# ... and move it below parent_group_layer
map.addLayerToGroup(parent_group_layer, child_group_layer)
map.removeLayer(child_group_layer)

# add group_layer_to_move_next_to_child_layer to the map ...
group_layer_to_move_next_to_child_layer = map.addLayer(lyrx_file)[0]
group_layer_to_move_next_to_child_layer.name = 'Group_Layer_to_Move_Next_to_Child_Layer'
# ... and try to move it next to child_group_layer
map.moveLayer(child_group_layer, group_layer_to_move_next_to_child_layer, "AFTER")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So initially, my map and the table of contents are empty:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MoveLayer_01.png" style="width: 338px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79627i942A8273E41E6433/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MoveLayer_01.png" alt="MoveLayer_01.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then, my script adds C (or &lt;FONT face="courier new,courier"&gt;parent_group_layer&lt;/FONT&gt;)&amp;nbsp; (line 10). Afterwards, B (or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;child_group_layer)&lt;/FONT&gt; &amp;nbsp;is added (line 14) and moved below C (line 17-18). In the next step, A (or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;group_layer_to_move_next_to_child_layer)&lt;/FONT&gt; is added to the map (line 21).&lt;/P&gt;&lt;P&gt;The table of contents now looks as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MoveLayer_02.png" style="width: 340px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79629i4C05D996F4D40CCE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MoveLayer_02.png" alt="MoveLayer_02.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Finally, I want to move A next to B (line 24). However, A is not placed as child of C and on the same hierarchy level as B, but on the same hierarchy level as C:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MoveLayer_03.png" style="width: 345px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79630iA1FE98EC1ABBAE71/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MoveLayer_03.png" alt="MoveLayer_03.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My intended result would look as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MoveLayer_04.png" style="width: 342px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79631iD028697C842E477F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MoveLayer_04.png" alt="MoveLayer_04.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How can I achieve my goal by using the &lt;FONT face="courier new,courier"&gt;map.moveLayer&lt;/FONT&gt; method?&lt;/P&gt;&lt;P&gt;I am running my script in the ArcGIS Pro Python Window.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 08:36:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1324658#M68510</guid>
      <dc:creator>lbd_bayern</dc:creator>
      <dc:date>2023-09-01T08:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro: map.MoveLayer not working as expected</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1324722#M68511</link>
      <description>&lt;P&gt;Try &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/map-class.htm#:~:text=through%20addLayer.-,addLayerToGroup%20(target_group_layer%2C%20add_layer_or_layerfile%2C%20%7Badd_position%7D),-Parameter" target="_blank" rel="noopener"&gt;addLayerToGroup() instead&lt;/A&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the documentation:&amp;nbsp;&lt;SPAN&gt;The&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;addLayerToGroup&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;method is the only way to add a layer or collection of layers into an existing, empty group layer in a map.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 13:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1324722#M68511</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-09-01T13:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro: map.MoveLayer not working as expected</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1326276#M68541</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;thanks for your reply, and good to know that this restriction is explicitly stated in the documentation. I was able to solve my problem with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class=""&gt;addLayerToGroup&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;()&lt;/FONT&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 08:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-map-movelayer-not-working-as-expected/m-p/1326276#M68541</guid>
      <dc:creator>lbd_bayern</dc:creator>
      <dc:date>2023-09-07T08:42:28Z</dc:date>
    </item>
  </channel>
</rss>

