f.write(str(row.getValue("parcels.OBJECTID")) + ", " + str(row.getValue("parcels.LU_CODE")) + ", " + str(row.getValue("parcels.ZONE_CODE")) + "\n")
import arcpy from arcpy import env try: mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] Parcels = "parcels" fc = arcpy.mapping.ListLayers(mxd, Parcels, df)[0] f = open(r"Y:\Notification Radius Pkgs\Setup10\Test\Test.txt", 'w') # Create a search cursor rows = arcpy.SearchCursor(fc) for row in rows: f.write(str(row.getValue("OBJECTID")) + "\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))
Oh, your field limiters are taking out OBJECTID...rows = arcpy.SearchCursor(fc,"","","TOWNSHIP; RANGE; SEC; SUBCODE; BLOCK; LOT","") Oh sorry, after testing even that should work, I guess OBJECTID is protected from field limiters. Not sure what your issue is, works fine even with the non raw path and improper indentation.
rows = arcpy.SearchCursor(fc,"","","TOWNSHIP; RANGE; SEC; SUBCODE; BLOCK; LOT","")
rows = arcpy.SearchCursor("parcels") for row in rows: print row.getValue("OBJECTID")
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 like rows = arcpy.SearchCursor("parcels") for row in rows: print row.getValue("OBJECTID") Then add on line by line until you run into a wall.
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))
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
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
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.