Yes, this will get you!
The trick here is to do the GetCount inside the calculate value. A little Python goes a long way in ModelBuilder!
"Output feature class" is the model element for your shapefile that you want to delete if it is empty.
You should have Output feature class be precondition for this Calculate Value tool so it will run at the right time.
expression:
DeleteIfZeroCount(r"%Output feature class%")
code block:
def DeleteIfZeroCount(inFC): import arcpy if int(arcpy.GetCount_management(inFC).getOutput(0)) == 0: arcpy.Delete_management(inFC) return True else: return False
followed by error 000732 input rows for my "target shapfile" does not exist or is not supported failed to execute (getcount)
import arcpy invalue = arcpy.Getparameter (0) if inValue == 0: outValue = True Else: out Value = False Arcpy.SetParameter(1, outValue)
Hi Lee
I know it's been a long time since you posted this question and solution, but do you mind sending a picture of your model? -If you still have it?
I am having the same problem as you where I am not able to delete empty feature classes created by my model. I've tried many things and contacting you is sort of my last resort.
Kind regards
Andreas
I think the easiest way may be to do the delete inside the Calculate Value tool. This is up-thread, but here's another shot at it.
As I said above it's very important that you use the "r" and quotes and percent signs as shown - and that the name matches the name of the model element exactly.
Expression:
DeleteIfEmpty(r"%Shapefile output%")
Code block:
import arcpy def DeleteIfEmpty(ds): fcount = int(arcpy.GetCount_management(ds).getOutput(0)) if fcount == 0: arcpy.Delete_management(ds)