LEA_Publish

Trouble Using a Definition Query Inside Python ExportReport command

Discussion created by LEA_Publish on Sep 26, 2016
Latest reply on Sep 26, 2016 by BWhite-esristaff

Warning: Novice Python user!!

I found a great script that will iterate through a feature class and create a separate PDF for each feature using the ExportReport function from the Python Window in ArcMap.  It works great if I set the dataset_option to "ALL" but that produces a separate PDF for each feature with all of the reports in each PDF.  The example that I found includes a definition query for the dataset_option, which should only include one report per PDF, but that is the part that I keep getting an error for.  I can't get the report_definition_query to work.

 

Any suggestions on how to fix the report definition query?  I've been trying to get this to work off an on for a while now, so this would be a great help.  

 

As a side note, the only reason that I need to do this rather than simply export all of the reports directly from Report Designer is that my reports are rich in images and I can't export more than one report at a time using said Report Designer...

 

Here is the my code with the query that currently is causing an error (error is listed below code).  

 

>>> import arcpy
... mxd = arcpy.mapping.MapDocument(r"C:\\Users\\MCrow.SMEINC\\Desktop\\reporttry.mxd")
...
... df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
...
... lyr = arcpy.mapping.ListLayers(mxd, "Form_3", df)[0]
...
... fc = 'C:\\Users\\MCrow.SMEINC\\Downloads\\Lookout_MountainExport\\1929dd550983485a8f0c17a7ac69f007.gdb\\Form_3'
...
... Fields = ['ManholeID']
...
... with arcpy.da.SearchCursor(fc, Fields) as cursor:
... for row in cursor:
...
... manhole = (row[0])
...
... arcpy.mapping.ExportReport(lyr,
... r"C:\\Users\\MCrow.SMEINC\\Desktop\\ManholeInspections with Pipes.rlf",
...
... r"C:\\Users\\MCrow.SMEINC\\Desktop\\exportreport\ProjectReport"+str(manhole)+".pdf",
...
... "DEFINITION_QUERY",
...
... report_definition_query="ManholeID="+str(manhole)+"")
...
... del mxd

 


Here is the error:

 

 

Runtime error
Traceback (most recent call last):
File "<string>", line 35, in <module>
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\mapping.py", line 532, in ExportReport
return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True))
RuntimeError: Error in generating report

 

I am using ArcGIS 10.4.1 and running it on Windows 7 Professional 64 bit.  Python 2.7

 

Any suggestions would be very much appreciated.

Outcomes