1

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.

Code

Example of model an Calculata Value

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 18, 2015 at 10:36
5
  • One minor note, even though I do not think it is the cause of your problem: you do not need import arcpy in your code block. Commented Mar 18, 2015 at 11:59
  • Thank for the reply. Though, am I not importing arcpy in the second line in the block? Commented Mar 18, 2015 at 12:07
  • 1
    Yes, but you don't need to import the arcpy module if your Python code is running inside ArcMap -- only if externally. Commented Mar 18, 2015 at 12:09
  • I think that it would be easier if you did it all with a python script . There is probably a conflict here because you use getValue to run a tool that delet a fc which is used by getvalue as input. If you want to use a model, try with the result of your get value as a precondition and put the Delete tool in the main model Commented Mar 18, 2015 at 12:47
  • It actual works now. Commented Mar 18, 2015 at 13:01

1 Answer 1

1

Actually, it turns out that I had made an error with my preconditions. The code works and it deletes the empty feature classes. The only thing that now bothers me is that i don't recieve any warning messages arcpy.AddWarninng( 'Error in + 'inFC) .

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Mar 18, 2015 at 13:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.