2

I am looking to get a count on the polygonNieghbor and if it has polygons in it then I want to move to the next step MakeFeatureLayer. and If it doesn't have any features I would like it to finish.

Is there any other way to do this?

arcpy.GetCount_management(PolygonNeighbor_TableSelect)
arcpy.AddMessage(arcpy.GetMessages())

if arcpy.GetCount_management(PolygonNeighbor_TableSelect) > 0:
    arcpy.MakeFeatureLayer_management(MapUnitPolys, inFeatures_lyr)
 else
     print "done"
7

All geoprocessing tools produce a Results object. You want the first output of your GetCount results object. The output will be a string, so you also must convert the string to an integer.

if int (arcpy.GetCount_management(PolygonNeighbor_TableSelect) [0]) > 0:

  • so would I just replace if arcpy.GetCount_management(PolygonNeighbor_TableSelect) > 0: with if int (arcpy.GetCount_management(PolygonNeighbor_TableSelect) [0]) > 0: – Lbook Jun 12 at 20:36
  • Correct.You would. – Emil Brundage Jun 12 at 20:37
  • Now I get an SyntaxError: invalid syntax with else. – Lbook Jun 12 at 20:44
  • Check your indents. – Emil Brundage Jun 12 at 21:58
  • 1
    You're missing the colon as well. else: – Emil Brundage Jun 12 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.