AnsweredAssumed Answered

Get Count Equal Zero

Question asked by dmarkey on Jul 19, 2017
Latest reply on Jul 26, 2017 by dmarkey

I am wanting to execute a simple piece of Python code.

 

If selected features is one or more --> copy selected features to a predefined geodatabase

Else Print "No Features Selected"

 

But I am finding the GetCount selects all features within a featureclass when there is none pre-selected. How do I do this in Python? I am running the script from within ArcMap so the selected features within the data view window is processed.

 

Example script below:

 

# Import arcpy module
import arcpy
from arcpy import env
import sys
import os

arcpy.SetProgressorLabel("Processing Annotation Owner Layer")
arcpy.MakeFeatureLayer_management(r"Annotation\AnnotationOwner", "Layer")
selCountResult = arcpy.GetCount_management("Layer")
selCount = int(selCountResult.getOutput(0))
arcpy.AddMessage ("{0} Features Selected from Annotation Owner Layer".format(str(selCount)))
if selCount > 0:
    arcpy.CopyFeatures_management(r"Annotation\Maritime.DBO.AnnotationMisc", os.path.join(GDBName, "AnnotationMisc"))
    arcpy.AddMessage ("{0} Features Copied From Annotation Owner Layer".format(str(selCount)))
else:
    arcpy.AddMessage("Nothing Copied from Annotation Owner Layer")
arcpy.Delete_management("Layer","")

Outcomes