I am trying to delete empty feature classes created in the process of intersecting layers with a set-up in modelbuilder. By using Calculate Value tool i have written a code that should do the trick.
It is suppose to get count and if it is equal to zero then employ delete_management, which should delete the feature class. Else, do nothing and add a warning.
Some way along, it is not doing what I want. The model is creating my feature classes but even though some of them are empty they are not deleted. The report states that:
" Start Time: Wed Mar 18 11:15:09 2015 WARNING 000117: Warning empty output generated. Succeeded at Wed Mar 18 11:15:20 2015 (Elapsed Time: 11,44 seconds) Executing (Calculate Value): CalculateValue DeleteIfZeroCount(r"M:\HAL\TeamNIS\Tools\SOE_check\Models\Version1\Results\TestIntersectOnWhole.gdb\NaturalFeaturesA_PortsAndServicesA_Intersect") "def DeleteIfZeroCount(inFC) :\n import arcpy\n if int(arcpy.GetCount_management(inFC).getOutput(0)) == 0:\n arcpy.Delete_management(inFC)\n return True\n else:\n arcpy.AddWarning('Error in '+inFC)\n return False" Boolean Start Time: Wed Mar 18 11:15:21 2015 The process did not execute because the precondition is false. Succeeded at Wed Mar 18 11:15:21 2015 (Elapsed Time: 0,00 seconds) "
So, even though the feature class is empty, my Calculate Value tool doesn't delete the feature class. I am a newbie at coding including arcpy, so I might have made an obvious mistake. The question is why it won't delete the empty file? What is wrong with my code? The model and code is shown in the attached image, please state if you need more info.
import arcpy
in your code block.