AnsweredAssumed Answered

RemoveLayer not working

Question asked by YvesAllaire on Feb 13, 2020
Latest reply on Feb 13, 2020 by YvesAllaire

Hi,

 

I've tried a few different approach to remove a layer from the TOC, but none so far works.

 

The ultimate goal is to add the layer to a group, then remove it from the TOC

 

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

addLayer =arcpy.mapping.Layer("C:\TEMP\ArcGIS\HighLake2004\Group.lyr")
arcpy.mapping.AddLayer(df,addLayer)

tgl=arcpy.mapping.ListLayers(mxd, "Group", df)[0]

lyr = arcpy.mapping.Layer(OutPutLayer)
arcpy.mapping.AddLayer(df, lyr)

 

arcpy.mapping.AddLayerToGroup(df,tgl,lyr)


arcpy.mapping.RemoveLayer(df,lyr)
arcpy.RefreshTOC()

 

Then I have another question, even if I remove them after in ArcGIS, they are still available in my script parameters...

Outcomes