Solved! Go to Solution.
Problem! Can't have it read the layer inside the mxd because every grid layer is named differently. We have to have the user chose the feature class where it will find the Sheet_Id field to compare. Please check the code to see if I changed it correctly? Thanks!import arcpy, os, sys 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) fc_path = arcpy.GetParameterAsText(2) report = {} page_list = [] #Use Search Cursor to go through Attribuite Table to get Sheet number info for mapDoc in mxdList: mxd = arcpy.mapping.MapDocument(mapDoc) for lyr in m.ListLayers(mxd): if lyr.dataSource == fc_path: (So here I would delete the if lyr.supports("Datasource) so that it doesn't try to find the layer correct?) max_list = [] rows = arcpy.SearchCursor(mxdList, "Sheet_ID") for row in rows: max_list.append(row.Sheet_ID) sheet_count = max(max_list) arcpy.AddMessage('Sheet count: {0}'.format(sheet_count)) else: arcpy.AddError('No Layers in %s match data source'%mapDoc) pdfDoc = arcpy.mapping.PDFDocumentOpen(path)
print pdfDoc.pageCount
#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program import arcpy, os, sys 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) fc_path = arcpy.GetParameterAsText(2) report = {} for mapDoc in mxdList: arcpy.AddMessage(mapDoc) mxd = arcpy.mapping.MapDocument(mapDoc) for lyr in m.ListLayers(mxd): if lyr.supports('DATASOURCE'): if lyr.dataSource == fc_path: 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) page_list = [] # List all PDF's in the pdf_path folder arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): pname = ''.join([a for a in pdf_doc.split('.')[0] if a.isalpha()]) mname = p.basename(mapDoc.replace('_','')).split('.')[0] if pname == mname: page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))) page_count = max(page_list) arcpy.AddMessage('Page Count: %s'%page_count) print 'Page Count: %s'%page_count if page_count == sheet_count: arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc)) print '%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc) else: report[mapDoc] = pdf_doc # Report maps that do not match up if len(report) > 0: f = open(p.join(ws,'Page_Report.txt'),'w') for k,v in report.iteritems(): f.write('"%s" Sheet Count does not match number of pages in "%s"\n\n' %(k,v)) f.close() arcpy.AddMessage('Created report for map documents and PDF\'s') print 'Created report for map documents and PDF\'s' else: arcpy.AddMessage('All PDF\'s have the correct amount of pages') print 'All PDF\'s have the correct amount of pages'
"C:\Users\GIS\Desktop\DDP\mxd\other_map.mxd" Sheet Count does not match number of pages in "other_map3.pdf"