import arcpy from arcpy import env mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "ParcelDF")[0] Parcels = "parcels" fc = arcpy.mapping.ListLayers(mxd, Parcels, df)[0] f = open("Y:\Notification Radius Pkgs\Setup10\Test.txt", 'w') rows = arcpy.SearchCursor(fc, "OBJECTID < 5") fields = arcpy.ListFields(fc) record = [] for row in rows: for field in fields: if field.type != "Geometry": ##print "%s: Value = %s" % (field.name, row.getValue(field.name)) record.append(row.getValue(field.name)) for item in record: f.writelines("%s\n" % item) record = [] f.close() del row, rows
import arcpy from arcpy import env mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "ParcelDF")[0] Parcels = "parcels" fc = arcpy.mapping.ListLayers(mxd, Parcels, df)[0] f = open("Y:\Notification Radius Pkgs\Setup10\Test.txt", 'w') rows = arcpy.SearchCursor(fc) for row in rows: f.write(str(row.getValue("OBJECTID")) + ", " + str(row.getValue("LU_CODE")) + ", " + str(row.getValue("ZONE_CODE")) + "\n") f.close() del row, rows
rows = arcpy.SearchCursor("parcels") for row in rows: print row.getValue("OBJECTID")
tags (using # symbol above) to preserve indentation.
import arcpy from arcpy import env try: mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "ParcelDF")[0] Parcels = "parcels" fc = arcpy.mapping.ListLayers(mxd, Parcels, df)[0] f = open("Y:\Notification Radius Pkgs\Setup10\Test.txt", 'w') # Create a list of fields fields = arcpy.ListFields(fc, "", "") # Create a search cursor rows = arcpy.SearchCursor(fc,"","","TOWNSHIP; RANGE; SEC; SUBCODE; BLOCK; LOT","") for row in rows: f.write(str(row.getValue("OBJECTID")) + "\n") # Previous attempts- # f.writelines(str(row.getValue("TOWNSHIP")) + ", " + "\n") # (row.getValue("TOWNSHIP") + ", " str(row.getValue("RANGE")) + ", " + str(row.getValue("SEC")) + ", " + str(row.getValue("SUBCODE")) + ", " + str(row.getValue("BLOCK")) + ", " + str(row.getValue("LOT")) + "\n") f.close() del row, rows except Exception, e: import traceback f.close map(arcpy.AddError, traceback.format_exc().split("\n")) arcpy.AddError(str(e))
rows = arcpy.SearchCursor(fc,"","","TOWNSHIP; RANGE; SEC; SUBCODE; BLOCK; LOT","")
Hi Dave, I tested Jake's script and it works fine for me. Are you using proper syntax/indentation? Is there a field called "OBJECTID"? Do you have write access to that directory on Y-drive? Not sure what would be causing this issue.
Try something simple likerows = arcpy.SearchCursor("parcels") for row in rows: print row.getValue("OBJECTID")
Then add on line by line until you run into a wall.