I am trying to figure out how to delete the layer that is created during the Buffer_analysis line. I have searched all over the internet and have honestly tried about 100 different methods and cannot seem to find one that works. If I was to type a layer "name" I can delete the layer, but in this case the layer name will be dependent upon the user input at
"outPath = arcpy.GetParameterAsText(1)"
This is only my second script so this is kicking my butt, I have been googling the heck out of this just to get this far, we have had zero teaching in our online class (just told to read a chapter and write a code).
UPDATE: Here is my full script.
# William Herzig # Week 6 tool creation # 6 Aug 2019 import arcpy from arcpy import env arcpy.env.workspace = "\\\\SNHU-LABS-UTIL2.snhu-labs.com\\userprofiles$\\william.herzig\\Documents\\programming\\module_5_data\\week_5.gdb" arcpy.env.overwriteOutput = True # List of all variables for the script # User input variables (parameters) # Input parameters for buffer tool inPath = arcpy.GetParameterAsText(0) outPath = arcpy.GetParameterAsText(1) bufferDistance = arcpy.GetParameterAsText(2) inPath1 = arcpy.GetParameterAsText(3) outPath1 = arcpy.GetParameterAsText(4) bufferDistance1 = arcpy.GetParameterAsText(5) inPath2 = arcpy.GetParameterAsText(6) outPath2 = arcpy.GetParameterAsText(7) bufferDistance2 = arcpy.GetParameterAsText(8) # Input parameter Master Shape, used for clip tool, erase tool and Master Shape layer natPark = arcpy.GetParameterAsText(9) # Input variable for the final output feature class finalOutput = arcpy.GetParameterAsText(10) # Pre-defined variables buffered_area = "buffered_area" clip = "clip" clip1 = "clip1" clip2 = "clip2" layer_name = finalOutput layer_name1 = "Master Shape" mxd = arcpy.mapping.MapDocument("CURRENT") df=arcpy.mapping.ListDataFrames(mxd, "*") layerList = arcpy.mapping.ListLayers(mxd, "", df) # Clip tool, clipping the 3 input feature classes to the Master Shape. This will reduce clutter and time due to less features for the buffer tool arcpy.Clip_analysis(inPath, natPark, clip, "") arcpy.Clip_analysis(inPath1, natPark, clip1, "") arcpy.Clip_analysis(inPath2, natPark, clip2, "") # Buffer tool, places a user defined buffer around each of the 3 input feature classes and exports to the user defined feature classes, also adds as a layer to the map buffer1 = arcpy.Buffer_analysis(clip, outPath, bufferDistance) buffer2 = arcpy.Buffer_analysis(clip1, outPath1, bufferDistance1) buffer3 = arcpy.Buffer_analysis(clip2, outPath2, bufferDistance2) # Union tool makes a single feature class by combining the 3 buffer outputs into one arcpy.Union_analysis([buffer1, buffer2, buffer3], buffered_area, "ALL", "", "GAPS") # Erase tool erases the Union features from the Master Shape (natPark parameter) and saves as the finalOutput parameter feature class arcpy.Erase_analysis(natPark, buffered_area, finalOutput, "") # Adds a layer for the Master Shape (natPark parameter) arcpy.MakeFeatureLayer_management(natPark, layer_name1) add_layer1 = arcpy.mapping.Layer(layer_name1) arcpy.mapping.AddLayer(df, add_layer1) # Adds a layer for the finalOutput parameter (the result of the erase tool) arcpy.MakeFeatureLayer_management(finalOutput, layer_name) add_layer = arcpy.mapping.Layer(layer_name) arcpy.mapping.AddLayer(df, add_layer)