Get Count (Data Management)
Returns the total number of rows for a feature class, table, layer, or raster.
You can view the returned row count in the Results window.
If the input is a layer or table view containing a selected set of records, only the selected records will be counted.
This tool honors the Output Extent environment. Only those features that are within or intersect the Output Extent environment setting will be counted.
In ModelBuilder, Get Count is typically used to set up a precondition, as illustrated below. In this model, Get Count counts the number of records returned by the Select tool. If the count is zero, Buffer will not run due to the precondition.
The input table view or raster layer. If a selection is defined on the input, the count of the selected rows is returned.
|Raster Layer; Table View|
The following Python Window script demonstrates how to use the GetCount function in immediate mode.
import arcpy from arcpy import env env.workspace = "C:/data/data.gdb" arcpy.GetCount_management("roads")
The following stand-alone script is an example of how to use the GetCount function in a scripting environment.
# Name: fcCount.py # Purpose: calculate the number of features in a featureclass # Import system modules import arcpy from arcpy import env env.workspace = "C:/data/Montgomery.gdb" lyrfile = "streets.lyr" result = int(arcpy.GetCount_management(lyrfile).getOutput(0)) print result