Solved! Go to Solution.
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
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()