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")
Solved! Go to Solution.
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?
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?
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
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")