Pro equivalent to arcpy.mapping.MoveLayer

727
3
Jump to solution
11-13-2020 10:09 AM
2Quiker
Occasional Contributor II

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")

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed 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)
3 Replies
DanPatterson
MVP Esteemed 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)
2Quiker
Occasional Contributor II

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

0 Kudos
2Quiker
Occasional Contributor II

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")

0 Kudos