Pro equivalent to arcpy.mapping.MoveLayer

104
4
Jump to solution
2 weeks ago
Highlighted
Occasional Contributor

I need to move some layers in my layout and I am not seeing how to do this in Pro through python. Am I not seeing it or is there no way to do this in Pro?

 

ArcMap

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "" ,df):
if lyr.name == "Sections":
moveLayer = lyr
if lyr.name == "TaxParcels":
refLayer = lyr
arcpy.mapping.MoveLayer(df,refLayer,moveLayer,"BEFORE")

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Regular Contributor

arcpy/mapping/layerfile-class 

moveLayer (reference_layer, move_layer, {insert_position})

Provides the ability to move a layer or group layer in a layer file to a specific location in the layer stack.

 

this move layer?


... sort of retired...

View solution in original post

Tags (1)
4 Replies
Highlighted
MVP Regular Contributor

arcpy/mapping/layerfile-class 

moveLayer (reference_layer, move_layer, {insert_position})

Provides the ability to move a layer or group layer in a layer file to a specific location in the layer stack.

 

this move layer?


... sort of retired...

View solution in original post

Tags (1)
Highlighted
Occasional Contributor

I tried to use the following but get error.

 

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
#for lyr in m.listLayers():
m.moveLayer("Taxparcels","Sections","BEFORE")

 

Error;

Traceback (most recent call last):
File "<string>", line 7, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1802, in moveLayer
return convertArcObjectToPythonObject(self._arc_object.moveLayer(*gp_fixargs((reference_layer, move_layer, insert_position), True)))
ValueError: Sections

Reply
0 Kudos
Highlighted
Occasional Contributor

I was able to move the layer. Thanks.

 

aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
for lyr in m.listLayers():
print("Map: {0} Layers".format(lyr.name))
for lyr in m.listLayers():
if lyr.name == "Sections":
moveLayer = lyr
if lyr.name == "Taxparcels":
refLayer = lyr
m.moveLayer(refLayer,moveLayer,"BEFORE")

Reply
0 Kudos
Highlighted
New Contributor III

This moveLayer (for the map class) is not going to be retired I hope: https://pro.arcgis.com/en/pro-app/arcpy/mapping/map-class.htm

Reply
0 Kudos