I have about 30 geodatabases with about 15 feature classes in each database. Is there a way to have a script check the attribute tables to see if they're not attributed? If it could then select the features that don't have attributes and export them to a gdb or shp. I want an easy way to check the tables for nulls that I could run nightly. Would a searchcursor work for this? Is this possible?
Here is a little script I put together to find features with fields that are null. It will write to the report file what feature class and OID the feature is. It stops at the first null value so it wont report every bad field or give multiple reports for the same feature.
import arcpy, os, sys InWorkspace = sys.argv OutReportFile = sys.argv arcpy.env.workspace = InWorkspace # open the report file (overwrite) and write the header line OFhandle = open(OutReportFile,"w") OFhandle.write("FeatureClass,OID\n") for fc in arcpy.ListFeatureClasses(): # some basic information about the feature class fList = arcpy.ListFields(fc) # all the fields desc = arcpy.Describe(fc) OIDname = desc.OIDFieldName # the OID/FID field name, skipped later SHPname = desc.shapeFieldName# the shape field name, not checked in the same way sc = arcpy.SearchCursor(fc) for feat in sc: # assume no null fields for now FoundNullField = False for field in fList: # for every field that the feature class has if field.name.lower() != OIDname.lower() and field.name.lower() != SHPname.lower(): # so long as it's not the OID/FID field or the shape if not FoundNullField: if feat.isNull(field.name): # write to console and file, flag that a null field is found # so that the row isn't reported many times print "field is null: " + field.name FoundNullField = True OFhandle.write(fc + "," + str(feat.getValue(OIDname)) + "\n") del sc # clean up the cursor otherwise it leaves a lock OFhandle.close()
There are other types of empty like "" which aren't checked by the script and it doesn't go down the feature dataset tree, to do that use ListDatasets() in the database and set your workspace to each one to get the feature classes.
This program works but it is intended to be a template to expand upon with your knowledge of your data structure; it will run in a batch file:
Script.py path\Geodatabase.gdb otherpath\reportfile.csv