AnsweredAssumed Answered

arcpy.mapping.RemoveLayer question

Question asked by cwholmes on Mar 1, 2019
Latest reply on Mar 1, 2019 by cwholmes

Hello all,

I have a function that looks like:

 

def RemoveLayers(mxd,layers):
    arcpy.AddMessage('RemoveLayers-mxd: ' + mxd)
    arcpy.AddMessage('RemoveLayers-layers: ' + layers)
    mxd = arcpy.mapping.MapDocument(mxd)
    df=arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
    for lyr in arcpy.mapping.ListLayers(mxd):
        if lyr.name.upper() in (layers):
            arcpy.mapping.RemoveLayer(df, lyr)
            arcpy.AddMessage('Layer {} has been removed.'.format(lyr))
               
    mxd.save()
    del mxd

The line being used to call the function is:

 

RemoveLayers(ProposedMxd,"'OP_SITE_MNT','LU_BOUNDARY_MNT - OUTLINE','LU_BOUNDARY_MNT - WHITE FILLED','COMM_BOUNDARY_MNT'")

What I see as output is:

Any ideas as to why these 2 layers in red are also being removed, what am I missing?

Thanks!

Outcomes