I am trying to do the following in Python 2.7:
- Clip all files in a geodatabase with a single layer (so a batch clip)
- Export the resulting clip layers (identified with _clip on the end of their names) to _ready layers, only pulling out features with a Shape_Area under 100,000
- Delete the _clip layers to clean up the GDB.
I am doing all of this within 2 File GDBs. I originally created a model in ArcMap 10.6 ModelBuilder to get the basis, then exported to Python and rewrote it so it can be used outside of a toolbox.
I find when I run the below code, it finishes doing the clip successfully (result can be seen in the GDB), then basically skips over the rest with no error or result.
I am very new to Python, so suspect I have missed a core principle. Maybe you cannot have 2 for loops defined like this. If I separate them and run as two different scripts each process works fine, which tells me the construct of each process is correct, but combining them in this way is not.
Can someone guide me as to what I am doing wrong here?
I have done much research on Google to no avail.
I have altered path and file names to generic ones.
#IMPORT MODULES import os import arcpy #SET ENVIRONMENT arcpy.env.workspace = "E:\\Folder\\GDB_Name.gdb" arcpy.env.overwriteOutput = True #SET VARIABLES inputfc = arcpy.ListFeatureClasses() clipExtent = "Database Connections\\My Connection.sde\\My Layer" inputfc2 = arcpy.ListFeatureClasses("*.clip") outLocation = "E:\\Folder\\Another GDB Name.gdb" Delete_succeeded = "true" #PROCESSES #CLIP for fc in inputfc: arcpy.Clip_analysis(fc, clipExtent,fc + "_clip") #FC TO FC for fc in inputfc2: arcpy.FeatureClassToFeatureClass_conversion(fc, outLocation, fc + "_ready","Shape_Area > 100000") #DELETE CLIPS for fc in inputfc2: arcpy.Delete_management(fc, "")