Solved! Go to Solution.
"are there other tokens besides what's listed on the help pages?" and/or "is there a EVERYTHINGBUTSHAPE@ token?".
def GetFieldList(in_fc, list_all=False, plus_oid=False, return_shape=False, other_geom=False, return_object=False, exclude_fields=[]): type_list = ['OID','Geometry'] Exclude = ['shape_area','shape_length'] if list_all: other_geom=True plus_oid=True return_shape=True if plus_oid: type_list.remove('OID') if return_shape: type_list.remove('Geometry') if other_geom: Exclude = [] if len(exclude_fields) > 0: for ex_f in exclude_fields: Exclude.append(ex_f.lower()) # return either field names or field objects if return_object: field_list = [f for f in arcpy.ListFields(in_fc) if f.type not in type_list and f.name.lower() not in Exclude] else: field_list = [f.name for f in arcpy.ListFields(in_fc) if f.type not in type_list and f.name.lower() not in Exclude] return field_list
in_fc = r'path\to_your\featureClass' fields = GetFieldList(in_fc)
in_fc = r'path\to_your\featureClass' # Get all but shape fields = GetFieldList(in_fc, plus_oid=True, other_geom=True)
types = ['OID','Geometry'] other_geom = ['shape_area','shape_length'] field_list = [f.name for f in arcpy.ListFields(in_fc) if f.type not in types and f.name.lower() not in other_geom]
You can get all the fields except for the Shape and other geometry pretty easily:
[... see below]
"are there other tokens besides what's listed on the help pages?" and/or "is there a EVERYTHINGBUTSHAPE@ token?".
def GetFieldList(in_fc, list_all=False, plus_oid=False, return_shape=False, other_geom=False, return_object=False, exclude_fields=[]): type_list = ['OID','Geometry'] Exclude = ['shape_area','shape_length'] if list_all: other_geom=True plus_oid=True return_shape=True if plus_oid: type_list.remove('OID') if return_shape: type_list.remove('Geometry') if other_geom: Exclude = [] if len(exclude_fields) > 0: for ex_f in exclude_fields: Exclude.append(ex_f.lower()) # return either field names or field objects if return_object: field_list = [f for f in arcpy.ListFields(in_fc) if f.type not in type_list and f.name.lower() not in Exclude] else: field_list = [f.name for f in arcpy.ListFields(in_fc) if f.type not in type_list and f.name.lower() not in Exclude] return field_list
in_fc = r'path\to_your\featureClass' fields = GetFieldList(in_fc)
in_fc = r'path\to_your\featureClass' # Get all but shape fields = GetFieldList(in_fc, plus_oid=True, other_geom=True)
Why not just create a table view?
Why are you calling, what seems to be an exclusion list, "Keep"?
test = r'C:\TEMP\test2.gdb\roads' exclude = ['NAME1', 'TYPE1', 'Label1',' Display'] # Test plus OID and exclude fields and return as objects for field in GetFieldList(test,plus_oid=True,return_object=True,exclude_fields=exclude): print field.name, field.type, field.length
is there a token for: AllFieldsExceptShape@?
>>> searchRow = arcpy.da.SearchCursor(myFC, ["SHAPE@","*"]).next() >>> searchRow (<Polygon object at 0x2b713f0[0x2b68e80]>, 1, (1216836.715736469, 112885.83942983788), None, 5723.961799418091, 395403.18030676956, 1)
>>> searchRow = arcpy.da.SearchCursor(myFC, ["*"]).next() >>> searchRow (1, (1216836.715736469, 112885.83942983788), None, 5723.961799418091, 395403.18030676956, 1)
Maybe I didn't follow everything written above, but I have always used "*" to denote all the fields (except for SHAPE). So for example, if I want all the field AND SHAPE:>>> searchRow = arcpy.da.SearchCursor(myFC, ["SHAPE@","*"]).next() >>> searchRow (<Polygon object at 0x2b713f0[0x2b68e80]>, 1, (1216836.715736469, 112885.83942983788), None, 5723.961799418091, 395403.18030676956, 1)
but if I just want the non-geometry fields:>>> searchRow = arcpy.da.SearchCursor(myFC, ["*"]).next() >>> searchRow (1, (1216836.715736469, 112885.83942983788), None, 5723.961799418091, 395403.18030676956, 1)
Note that "*" will always return the centroid x,y coordinate pair... that's the (1216836.715736469, 112885.83942983788) part... but just not the entire geometry object.