I'm building a Python toolbox and when I run one of my tools, I noticed that the table of contents doesn't update itself in the drop down list of my Python tool. As you can see in the image below, some layers are present in the list and are not in the table of contents although I've updated my data frame (by the way all of these layers are created by a previously executed Python tool).
These are the functions I used to update my data frame, without any result:
Also, the increment after the GPLx layers adds up every time I re-execute the tool. This means that somewhere in the system, an identical layer is stored. That's why Python increments the layer number suffix (I guess).
I thought that ArcGIS probably stores the layer history somewhere so I looked for it but didn't find it.
Run the following tool and put any layer you have in the input parameter. Once it's done, remove the layer from your data frame and go back to re-execute the tool. You will notice in the drop down list that the removed layer is still there:
# -*- coding: utf-8 -*-
def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "LayerTest" self.alias = ""` # List of tool classes associated with this toolbox self.tools = [LayerTestTool]
def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "LayerTestTool" self.description = "" self.canRunInBackground = False def getParameterInfo(self): """Define parameter definitions""" params =  param_in = arcpy.Parameter( displayName="In Layer", name="Layer", datatype="GPFeatureLayer", parameterType="Required", direction="Input") params.append(param_in) param_out = arcpy.Parameter( displayName="out", name="out", datatype="GPFeatureLayer", parameterType="Derived", direction="Output") params.append(param_out) return params def isLicensed(self): """Set whether tool is licensed to execute.""" return True def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" return def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return def execute(self, parameters, messages): """The source code of the tool.""" Layer = parameters.valueAsText out = arcpy.MakeFeatureLayer_management(Layer, "myoutput") arcpy.SetParameterAsText(1, out) return