moveLayer fails on arc Pro 2.5

06-01-2020 09:50 AM
New Contributor

Tinkering and testing with mapping module in arc pro 2.5.0. The last line (moveLayer) of the following code fails. The failure shows 'value error' yet type testing of the function method inputs show <class 'arcpy._mp.Layer'>.

Why does the moveLayer method dislike my inputs?

import arcpy as g

# Get parameters
iLay = g.GetParameter(0)

# attach to activeMap

amp ="CURRENT").activeMap
wrkspc = "C:/Projects/ArcPro/GISTools/"

# add layer (actually empty group) from layerfile and rename

fLyr = +'newGrpLay.lyrx')
layNgrp = amp.addLayer(fLyr)[0] = 'Layer Group Jun'

# add layer given in tool input (this a re-add, layer already exists in map) = 'gvnLay1'
amp.addLayerToGroup(layNgrp, iLay)

# add second layer from layerfile and rename

fLyr2 = +'zeropt.lyrx')

lstAdd = amp.addLayer(fLyr2, 'TOP')
layObj = lstAdd[0] = 'lay_from_file'

# now change order of layers

amp.moveLayer(iLay, layObj)     ## fails;  regardless if position parameter is included

ValueError: <MappingLayerObject object at {address}>

Tags (2)
0 Kudos
1 Reply
MVP Frequent Contributor

I think the issue may be with this line: 

iLay = g.GetParameter(0)

The comments in your code suggest that this is a layer already in the map? If that is the case lets call it XYZ. These line rename the layer and then duplicates it by adding it to the group layer = 'gvnLay1'
amp.addLayerToGroup(layNgrp, iLay)

So you now have two layers called gvnLay1 in your contents panel, is that what you wanted? I assume the move is failing because it does not know which one you want to move it above?

0 Kudos