Wednesday 13 February 2019

arcpy - Using Search Cursor and Messaging Total Count of Items from Field in Layer that was Searched?


My program works but it is not displaying a message of the total sheet count found in attribute table that the search cursor searched through. For Example: It goes through the mxd chosen by user finds the layer with the name Grid in it and then is supposed to count the rows in the field Sheet_ID. End result is to print a message of the count found. My code is below:


import arcpy, os, sys

from os import path as p
from arcpy import mapping as m

mxdList = arcpy.GetParameterAsText(0).split(';')


sheet_count = ()

for mapDoc in mxdList:
arcpy.AddMessage(mapDoc)

mxd = arcpy.mapping.MapDocument(mapDoc)
for lyr in m.ListLayers(mxd, "*, Grid"):
if lyr.description == "*, Grid":
max_list = []
rows = arcpy.SearchCursor(lyr)
for row in rows:
max_list.append(row.Sheet_ID)
sheet_count = max(max_list)
arcpy.AddMessage('Sheet count: %s'%sheet_count)
print 'Sheet count: %s'%sheet_count

else:
arcpy.AddError('No Layers in %s match data source'%mapDoc)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...