Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I know this is something simple but for some reason I am having trouble remembering. In my code I am getting a name is not define for sheet_count. This means I would have to define at top correct. For Example: Is it sheet_count = true? My code is below:

import arcpy, os, sys, string
from os import path as p
from arcpy import mapping as m

#Make parameters for people to choose mxd and folder of PDFs to compare

mxdList = string.split(arcpy.GetParameterAsText(0), ";")
pdf_path = arcpy.GetParameterAsText(1)

#Use Search Cursor to go through Attribuite Table to get Sheet number info

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)
share|improve this question

1 Answer 1

So what I cannot tell because you did not format your python code is how the variable "sheet_count" is scoped.

If your code looks like this:

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

Then you have scoping issue as "sheet_count" does not exist outside of the for loop. So you should define "sheet_count" outside of the for statement like so:

sheet_count = 0
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
share|improve this answer
    
Thank You so much! That what it was. Where would I have gotten that information? (i.e. learn that) And how do I format Python code for these questions so I can do it right next time? –  Michelle Couden Mar 6 '13 at 21:09
1  
It just takes time to if you are just starting. You need to indent 4 spaces. This site uses markdown for text formatting: stackoverflow.com/editing-help –  Jamie Mar 6 '13 at 22:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.