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 have written a code to count sheets or pages in an mxd. How would I print a message before the display of the count result? For Example: the count is 11. I want it to display "Sheet Count : 11". 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 = arcpy.GetParameterAsText(0).split(";")
pdf_path = arcpy.GetParameterAsText(1)

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

count = 0
mxd_dict = {}
for mapDoc in mxdList:
    arcpy.AddMessage(mapDoc)
    mxd = arcpy.mapping.MapDocument(mapDoc)
    max_list = []
    for lyr in m.ListLayers(mxd):
        try:
            rows = arcpy.SearchCursor(lyr)
            for row in rows:
                max_list.append(row.Sheet_ID)
                count += 1
            sheet_count = max(max_list)
            mxd_name = p.basename(mapDoc).split('.')[0]
            mxd_dict[mxd_name] = sheet_count

        except:
            pass
arcpy.AddMessage (count)
 Right here is probably where I need the code. Sheet Count : 
share|improve this question
    
Please review some of your previous questions, do not just abandon them. This does not encourage the people that have tried to help you previously. –  blah238 Mar 11 '13 at 17:07
    
Thanks for the advice. But this is not the same question as before. This question is asking how I can display the rows counted in the result window when the code runs. For Example: Sheet Count = 11. –  Michelle Couden Mar 11 '13 at 17:32
    
It looks like exactly the same question to me, the only thing that has changed is a little bit of code which you can and should update in the original question by editing it. –  blah238 Mar 11 '13 at 17:35
    
Michelle, please click the checkmark next to @KHibma's answer to reflect that you have "accepted" his answer as best or what worked for you. Thanks. –  RyanDalton Mar 11 '13 at 18:37
add comment

marked as duplicate by blah238, Aaron, Devdatta Tengshe, Zachary, iant Mar 14 '13 at 10:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 5 down vote accepted

There are are number of ways you can write out messages with AddMessage. I personally prefer this way:

arcpy.AddMessage("Sheet count: {0}".format(count))

Sheet count: 11

You can continue to add more variables in that style, for example

arcpy.AddMessage("Processing sheet {0} of {1}".format(counter, total))

Processing sheet 2 of 30

share|improve this answer
    
Thank You so much for your help. The first one worked perfectly. Have a good day! –  Michelle Couden Mar 11 '13 at 17:34
add comment

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