3

I like to run some scripts from mxd. Very often I am using Make Feature Layer tool to facilitate queries.

Tool help says: “Creates a feature layer from an input feature class or layer file. The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved”.

Question:

How to remove newly created layer without closing mxd?

Note arcpy.mapping.RemoveLayer is not working on layer created that way or maybe I am doing something wrong here

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
FelixIP
  • 22,922
  • 3
  • 29
  • 61
  • Are you using the temporary layers for a purpose within ArcMap? If you can just use them "in memory", maybe you can set the arcpy.env.addOutputsToMap = False so that they never get added in the first place. Then when you terminate the ArcMap session the references should die too. – crmackey Feb 16 '16 at 03:08
  • 1
    The partner function to RemoveLayer is AddLayer. The partner to MakeFeatureLayer is Delete. – PolyGeo Feb 16 '16 at 03:12
  • Will check delete tomorrow, looks like solution. Thanks – FelixIP Feb 16 '16 at 04:05
  • Confirmed arcpy.Delete_management(lyr) works – FelixIP Feb 16 '16 at 20:33

0 Answers0