AnsweredAssumed Answered

Cleaning up temporary layers created by python toolbox script

Question asked by jacksonjw58 on Mar 24, 2014
Latest reply on Sep 15, 2014 by jamesfreddyc
ArcMap 10.2.1 / Python 2.7
I have several tools in a python toolbox. When I run through the tools in succession, temporary layers created in previously run tools show up as parameters in later tools.  These temporary layers are created with arcpy.MakeFeatureLayer_management and the corresponding feature classes are in the scratch workspace.  The layers show up in other tools for parameters where parameterType = GPFeatureLayer.

For example: Tool_A creates temporary layers temp1 and temp2 and then adds "Final Layer" to the TOC.  If I run Tool_B which takes a layer parameter, I would expect "Final Layer" to show up in the list but NOT layers temp1 & temp2.  The behavior I am seeing however is that all three layers show up as choices.

I am setting arcpy.env.addOutputsToMap = False at the beginning of each tool script and the temporary layers do not show up in the TOC as expected.  I also delete all layers from scratch at the end of each tool script.  Any help would be greatly appreciated.

Outcomes