"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)
import arcpy, os, sys def Main(): src = "" #Enter path to data here for field in fieldS: if field.type == 'Geometry' or field.type == 'OID' or 'shape' in str(field.name).lower(): pass else: print field.name if __name__=="__main__": Main()
import arcpy, os, sys def Main(): src = "" # Insert Path to data here excludeList = ['Geometry','OID','Raster','Guid','Blob'] fieldS = arcpy.ListFields(src) field_list = [] for field in fieldS: if any(field.type in s for s in excludeList) or 'shape' in str(field.name).lower(): pass else: field_list.append(field.name) print field_list return field_list if __name__=="__main__": Main()
import arcpy, sys, os from MyModules import GetFieldList inFC = arcpy.GetParameterAsText(0) # Input Feature Class (feature) PtFC = arcpy.GetParameterAsText(1) # Output Feature Class (point) pLocation = arcpy.GetParameterAsText(2) # Which end? [ start | end ] ##overwrite = arcpy.GetParameterAsText(3) # Boolean to control the overwrite of the output (not part of Esri's version) # WARNING! Existing feature class is automatically overwritten if arcpy.Exists(PtFC): arcpy.Delete_management(PtFC) PtFCpath = os.path.dirname( PtFC ) PtFCname = os.path.basename( PtFC ) arcpy.CreateFeatureclass_management( PtFCpath, PtFCname, "POINT", inFC, "DISABLED", "DISABLED", inFC ) # ASSERT: The following two returns from GetFieldList should be identical insertFields = GetFieldList(PtFC) searchFields = GetFieldList(inFC) insertFields.insert(0,"SHAPE@XY") # new points will get an XY tuple, not a geometry object searchFields.insert(0,"SHAPE@") # get the geometry *object* to get properties of it cShape = 0 newPoints = arcpy.da.InsertCursor(PtFC, insertFields) if ( pLocation == "START" ): srcFeatures = arcpy.da.SearchCursor(inFC, searchFields) for feature in srcFeatures: point = feature[cShape].firstPoint xy = (point.X, point.Y) newPoints.insertRow( (xy,) + feature[1:] ) elif ( pLocation == "END" ): srcFeatures = arcpy.da.SearchCursor(inFC, searchFields) for feature in srcFeatures: point = feature[cShape].lastPoint xy = (point.X, point.Y) newPoints.insertRow( (xy,) + feature[1:] ) ##elif ( pLocation == "" ): # Other options can be included here to more completely mimic the Esri tool else: arcpy.AddMessage("Unknown point location entered. Please enter START or END. Aborting!") sys.exit(1) del newPoints arcpy.RefreshActiveView()
import arcpy def GetFieldList(in_fc, list_all=False, return_oid=False, return_shape=False, return_other_geom=False, return_object=False, exclude_fields=[]): Exclude_Types = ['Blob','Geometry','Guid','OID','Raster'] Exclude = ['shape_area','shape_length','globalid','shape.len'] if list_all: return_other_geom=True return_oid=True return_shape=True if return_oid: Exclude_Types.remove('OID') if return_shape: Exclude_Types.remove('Geometry') if return_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 Exclude_Types and f.name.lower() not in Exclude] else: field_list = [f.name for f in arcpy.ListFields(in_fc) if f.type not in Exclude_Types and f.name.lower() not in Exclude] return field_list
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.
>>> 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)
is there a token for: AllFieldsExceptShape@?
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
Why not just create a table view?
You can get all the fields except for the Shape and other geometry pretty easily:[... see below]
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]
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.