Solved! Go to Solution.
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 maps = r"C:\Users\GIS\Desktop\DDP\mxd\map_book.mxd;C:\Users\GIS\Desktop\DDP\mxd\other_map.mxd" mxdList = maps.split(";") pdf_path = r'C:\Users\GIS\Desktop\DDP' ##mxdList = arcpy.GetParameterAsText(0).split(";") ##pdf_path = arcpy.GetParameterAsText(1) #Use Search Cursor to go through Attribuite Table to get Sheet number info sheet_count = 0 for mapDoc in mxdList: arcpy.AddMessage(mapDoc) print 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) sheet_count = max(max_list) print 'Sheet Count: %s' % sheet_count arcpy.AddMessage('Sheet Count: %s' % sheet_count) except: pass
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) #Use Search Cursor to go through Attribuite Table to get Sheet number info sheet_count = () for mapDoc in mxdList: arcpy.AddMessage(mapDoc) print mapDoc mxd = arcpy.mapping.MapDocument(mapDoc) max_list = [] for lyr in m.ListLayers(mxd, "*, Grid"): try: rows = arcpy.SearchCursor(lyr) for row in rows: max_list.append(row.Sheet_ID) sheet_count = max(max_list) print 'Sheet Count: %s' % sheet_count arcpy.AddMessage('Sheet count: %s'%sheet_count) except: pass
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 sheet_count = 0 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) sheet_count = max(max_list) print 'Sheet Count: %s' % sheet_count arcpy.AddMessage('Sheet Count: %s' % sheet_count) except: pass arcpy.env.workspace = ws = pdf_path for pdf_ in arcpy.ListFiles('*.pdf'): page_list = [] pdf_list = [] pdf = pdf_.split('.')[0].rstrip('0123456789') for doc in arcpy.ListFiles('%s*.pdf' % pdf): doc_ = doc.split('.')[0].rstrip('0123456789') if doc_ == p.basename(mapDoc).split('.')[0]: page_list.append(int(''.join([i for i in doc if i.isdigit()]))) page_count = max(page_list) print 'PDF Page Count: %s' %page_count arcpy.AddMessage('PDF Page Count: %s' %page_count) if page_count == sheet_count: arcpy.AddMessage('\n"%s" Sheet Count matches number of pages in %s.pdf\n' %(p.basename(mapDoc),doc_)) print '\n"%s" Sheet Count matches number of pages in %s.pdf\n' %(p.basename(mapDoc),doc_) else: arcpy.AddMessage('\n"%s" Sheet Count does not match number of pages in %s.pdf\n' %(p.basename(mapDoc),doc_)) print '\n"%s" Sheet Count does not match number of pages in %s.pdf\n' %(p.basename(mapDoc),doc_)
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 # MXD LIST 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) sheet_count = max(max_list) mxd_name = p.basename(mapDoc).split('.')[0] mxd_dict[mxd_name] = sheet_count except: pass # PDF LIST pdf_dict = {} pdf_list = [] arcpy.env.workspace = ws = pdf_path for pdf_ in arcpy.ListFiles('*.pdf'): pdf_list.append(pdf_.split('.')[0].rstrip('0123456789')) unique = list(set(pdf_list)) for pdf in unique: for doc in arcpy.ListFiles('%s*.pdf' % pdf): page_list = [] doc_ = doc.split('.')[0].rstrip('0123456789') for key in mxd_dict.keys(): if doc_ == key: page_list.append(int(''.join([i for i in doc if i.isdigit()]))) page_count = max(page_list) pdf_dict[doc_] = page_count # REPORT RESULTS for pdf in unique: print 'MXD:\t%s\tSheet Count:\t%s'%(pdf, mxd_dict[pdf]) arcpy.AddMessage('MXD:\t%s\tSheet Count:\t%s'%(pdf, mxd_dict[pdf])) print 'PDF:\t%s\tPage Count:\t%s'%(pdf, pdf_dict[pdf]) arcpy.AddMessage('PDF:\t%s\tPage Count:\t%s'%(pdf, pdf_dict[pdf])) if mxd_dict[pdf] == pdf_dict[pdf]: arcpy.AddMessage('\n"%s.mxd" Sheet Count matches number of pages in %s.pdf\n' %(pdf,pdf)) print '\n"%s.mxd" Sheet Count matches number of pages in %s.pdf\n' %(pdf,pdf) else: arcpy.AddMessage('\n"%s.mxd" Sheet Count does not match number of pages in %s.pdf\n' %(pdf,pdf)) print '\n"%s.mxd" Sheet Count does not match number of pages in %s.pdf\n' %(pdf,pdf)
i am getting a exceptions.KeyError'>:u'Amarillo_Base_Map'. Which is wierd where is it getting the u?
The error means this : exception KeyError
Raised when a mapping (dictionary) key is not found in the set of existing keys.
Could it be that there are 22 pdfs and the numbers in the program only go up to 9. So should I make them infinity because Houston has 154 pages.