#Purpose: Compares SheeID field to the toal PDFs created from Data Driven Pages Program import arcpy, os, sys #Make parameters for people to choose mxd and folder of PDFs to compare mxdList = string.split(arcpy.GetParameterAsText(0), ";") dir = arcpy.GetParameterAsText(1) fc_path = arcpy.GetParameterAsText(2) for mapDoc in mxdList: arcpy.mapping.MapDocument(mapDoc) for lyr in m.ListLayers(mxd): if lyr.supports('DATASOURCE'): if lyr.dataSource == fc_path: max_list = [] rows = arcpy.SearchCursor(fc_path, "Sheet_ID") for row in rows: max_list.append(row.Sheet_ID) pdf_count = max(max_list) arcpy.AddMessage('Sheet count: %s'%pdf_count) else: arcpy.AddError('No layers in %s match data source'%mapDoc)
pdfDoc = arcpy.mapping.PDFDocumentOpen(path) print pdfDoc.pageCount
The pdfs are created from the one mxd. For example: Abilene has 11 sheets (data driven pages) so when that tool makes the PDFs it makes 11 PDFS. One for each sheet or Data driven page.
#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.mapping.MapDocument(mapDoc) for lyr in m.ListLayers(mxd): if lyr.supports('DATASOURCE'): if lyr.dataSource == fc_path: max_list = [] rows = arcpy.SearchCursor(fc_path, "Sheet_ID") for row in rows: max_list.append(row.Sheet_ID) pdf_count = max(max_list) arcpy.AddMessage('Sheet count: %s'%pdf_count) else: arcpy.AddError('No layers in %s match data source'%mapDoc) # List all PDF's in the pdf_path folder arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): if ''.join([a for a in pdf_doc.split('.')[0] if a.isalpha()]) == mapDoc.replace('_',''): pdf = p.join(ws, pdf_doc) pdf_object = arcpy.mapping.PDFDocumentOpen(pdf) page_count = pdf_object.pageCount if page_count == pdf_count: arcpy.AddMessage('%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')) 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') else: arcpy.AddMessage('All PDF\'s have the correct amount of pages')
#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 = {} page_list = [] for mapDoc in mxdList: arcpy.mapping.MapDocument(mapDoc) for lyr in m.ListLayers(mxd): if lyr.supports('DATASOURCE'): if lyr.dataSource == fc_path: max_list = [] rows = arcpy.SearchCursor(fc_path, "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) # List all PDF's in the pdf_path folder arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('%s*.pdf' %mapDoc): page_list.append(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()])) page_count = max(page_list) if page_count == sheet_count: arcpy.AddMessage('%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')) 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') else: arcpy.AddMessage('All PDF\'s have the correct amount of pages')
#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 = {} page_list = [] 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) else: arcpy.AddError('No layers in %s match data source'%mapDoc) # List all PDF's in the pdf_path folder arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))) page_count = max(page_list) if page_count == sheet_count: arcpy.AddMessage('%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')) 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') else: arcpy.AddMessage('All PDF\'s have the correct amount of pages')
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
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)
#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"
Yep, that is what I think. Please, take a look at the code to see if I changed stuff correctly. I figured out to use ListLayers. See how close I am. 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 = string.split(arcpy.GetParameterAsText(0), ";") pdf_path = arcpy.GetParameterAsText(1) report = {} #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) df = arcpy.mapping.ListLayers(mxd, "*,Traff Proj")[0] 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) page_list = []
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 = string.split(arcpy.GetParameterAsText(0), ";") pdf_path = arcpy.GetParameterAsText(1) report = {} #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) df = arcpy.mapping.ListLayers(mxd, "*,Traff Proj")[0] 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) page_list = []
page_list = [] arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))) page_count = max(page_list) arcpy.AddMessage('PDF page count: %s' page_count) if page_count == sheet_count: arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc)) else: arcpy.AddMessage('%s Sheet Count does not match number of pages in %s' %(mapDoc,pdf_doc))
It doesn't like my code for sheet count. I've attached to error again for you. It finishes counting the PDFs but it is puzzled on how to give me a sheet count. Error is Sheet_count not defined. So wouldn't I need to write, sheet_count = arcpy.mapping.ListLayers.
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 = string.split(arcpy.GetParameterAsText(0), ";") pdf_path = arcpy.GetParameterAsText(1) report = {} #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) df = arcpy.mapping.ListLayers(mxd, "*,Traff Proj")[0] 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) else: arcpy.AddError('No Layers in %s match data source'%mapDoc) sheet_count = max(max_list) arcpy.AddMessage('Sheet count: %s'%sheet_count) print 'Sheet count: %s'%sheet_count page_list = [] arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))) page_count = max(page_list) arcpy.AddMessage('PDF page count: %s' page_count) if page_count == sheet_count: arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc)) else: arcpy.AddMessage('%s Sheet Count does not match number of pages in %s' %(mapDoc,pdf_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 = string.split(arcpy.GetParameterAsText(0), ";") 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) 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) page_list = [] # List all PDF's in the pdf_path folder arcpy.env.workspace = ws = pdf_path for pdf_doc in arcpy.ListFiles('*.pdf'): page_list.append(int(''.join([i for i in pdf_doc.split('.')[0] if i.isdigit()]))) page_count = max(page_list) arcpy.AddMessage('PDF Page Count: %s' %page_count) if page_count == sheet_count: arcpy.AddMessage('%s Sheet Count matches number of pages in %s' %(mapDoc,pdf_doc)) else: arcpy.AddMessage('%s Sheet Count does not match number of pages in %s' %(mapDoc,pdf_doc))
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.