Problem With Related Records in Reports

325
0
02-05-2019 07:33 AM
MichaelKohler
Occasional Contributor II

We are creating a workflow to output reports from desktop 10.6. The FGDB is simple with 1 polygon feature class, a table for services and a table for comments on an individual service. It is a CIP concept. A project has one or more services (ie predesign, design, construction....) and each one of the services can have one or more comments. 

When generating the reports, we created the report layout in desktop and saved the reports rlf file. The report will be generated by python and when we ran the script, an error was returned that said 'could not open report file.' So I checked paths as this is usually the problem with that error and everything is correct. I beat my head against a wall for a little while, because reasons... and ran into the below.

When I have a report with more than one level of related records, the 'could not open' error is returned. Exact same report with the 2nd level removed works just fine. I know both rlf's are good and run just fine in desktop but python goes bonkers. The script below is designed to export a data driven map and a report for each project and stitch them together. I attached sample data and the rlf files. 

import arcpy
Report_MapDoc= r"R:\Enterprise\MapDocs\misgis0380\Report\tst.mxd"
Pdfs = r"R:\Enterprise\MapDocs\misgis0380\Report\docs"
#Report_Layout = r"R:\Enterprise\MapDocs\misgis0380\Report\Report_wo_comments.rlf"
Report_Layout = r"R:\Enterprise\MapDocs\misgis0380\Report\Report_w_comments.rlf"
mxd = arcpy.mapping.MapDocument(Report_MapDoc)
ddp=mxd.dataDrivenPages
lyr = arcpy.mapping.ListLayers(mxd)[0]
print lyr.name          
print Report_MapDoc
print Report_Layout
print Pdfs
pg = -1
while pg <= ddp.pageCount:
    pg = pg + 1
    ddp.currentPageID = pg
    name = ddp.pageRow.getValue('CIPNumber')
    if name != 'default':
        pdfFile = '%s\\%s.pdf' % (Pdfs,str(name))
        pdfRpt = '%s\\rpt%s.pdf' % (Pdfs,str(name))        
        lyr.definitionQuery = "CIPNumber = '{}'".format(name)
        ddp.exportToPDF(pdfFile, 'CURRENT')
        arcpy.mapping.ExportReport(lyr,Report_Layout,pdfRpt)                        
        finalPdf = arcpy.mapping.PDFDocumentOpen(pdfFile)
        finalPdf.appendPages(pdfRpt)
        finalPdf.saveAndClose()
del mxd, ddp, lyr
print 'Finished processing!'
Tags (2)
0 Kudos
0 Replies