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 need some help on my program. I have the parameters set to ask user to pick an mxd and the folder where those data driven PDFs are located. I started with Search Cursor to create a list from the Sheet_ID field of an mxd. To get total number of pages of that mxd. Now I need to write in for the program, to compare the list created from the Sheet numbers to the number of PDFs created and tell me if there is a difference in the total count. For Example: If there are 1 out of 11 sheets for the mxd, then there should be 11 PDFs created and so on. MY code is below:

#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program
Import arcpy, os, string, sys

#Make parameters for people to choose mxd and folder of PDFs to compare
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
dir = arcpy.GetParameterAsText(1)

#Use Search Cursor to go through Attribuite Table to get Sheet number info
rows = arcpy.SearchCursor(mxdList, "Sheet_ID")

#Use list from Sheet_ID field to match the number of PDFs created to get difference 
share|improve this question

1 Answer 1

i = 0
for x in os.listdir(dir):
    if x.endswith(".pdf"):
        i = i + 1

I think this should work.

Edit:
.endswith is case sensitive, so you may want to populate a variable with the possible extensions like

extensions = '.pdf', '.PDF'

then the if statement becomes

if x.endswith(extensions)
share|improve this answer
    
Is my code for the Search Cursor correct? mxdList to grab the list the user created and Sheet_Id to name the field to make the list of total sheets. –  Michelle Couden Mar 1 '13 at 21:11
    
Oh, sorry. You don't need a search cursor for that, you can just iterate through your mxdList Array. For each element in that array you'll want to work some magic from arcpy.mapping to count the pages for each data driven page. help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/… –  HeyOverThere Mar 1 '13 at 21:52
    
My code gives me an "Exception raised while running script" it stops right after import arcpy, os, string, sys. –  Michelle Couden Mar 1 '13 at 21:53
    
You could also do x.lower().endswith(".pdf"). –  blah238 Mar 5 '13 at 2:46

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.