Select to view content in your preferred language

Arcpy Export report error

5651
8
04-16-2013 06:55 AM
DavidMeek
Deactivated User
Hello all,

I'm working on trying to use arcpy to automate the creation of a report, but I'm running into a problem.

  
>>> arcpy.mapping.ExportReport('2013pp',"C:\reports\2013_Graffiti.rlf","C:\reports\2013_Graffiti_report.pdf")

    Runtime error 
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
        return fn(*args, **kw)
      File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 506, in ExportReport
        assert isinstance(report_source, (MapDocument, TableView, Layer)), str(type(report_source))
    AssertionError: <type 'str'>


I'm having trouble deciphering the traceback as it seems to reference a variety of internal python files. In trouble shooting so far, I thought the problem might be that the report_source needs to be a layer file and I was using a .shp so I converted to a .lyr but then I get the error:

    Parsing error SyntaxError: invalid syntax (line 1)


Any advice would be greatly appreciated,
Best,
David
0 Kudos
8 Replies
ToddLusk
Regular Contributor
It's a problem with the file path strings.  Python is picky about the "slashes".  You have to either switch your "\" to "\\" or "/" or throw an "r" in front of the existing strings as you have them now.

"C:\\reports\\2013_Graffiti.rlf","C:\\reports\\2013_Graffiti_report.pdf"
OR
"C:/reports/2013_Graffiti.rlf","C:/reports/2013_Graffiti_report.pdf"
OR
r"C:\reports\2013_Graffiti.rlf",r"C:\reports\2013_Graffiti_report.pdf"
0 Kudos
JasonScheirer
Esri Alum
The first argument to exportreport must be an arcpy.mapping object. For example:

mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]
layer = arcpy.mapping.ListLayers(df, '2013pp')[0]
arcpy.mapping.ExportReport(layer,"C:\reports\2013_Graffiti.rlf","C:\reports\2013_Graffiti_report.pdf")
0 Kudos
deleted-user-mezzanRtr2IZ
Deactivated User
I am experiencing problems with arcpy.mapping.Exportreport as well since my desktop was updated to 10.2.1 earlier this week. I am attempting to export a .pdf report but encounter the follwing error:

Traceback (most recent call last):
File "C:\Users\Jeff\Documents\WORK\RECOVER\GetFireReportsData.py", line 69, in <module>
arcpy.mapping.ExportReport(lyr, rlf, (r"C:/Data/RECOVER2/" + fireName + "Fire_detailed.pdf"))
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 515, 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

This is the function, pretty simple. It was working fine and the .pdf report was successfully generating last week when I was running 10.2.0. Can anybody tell me what is going on (mind that this is just part of a larger program, obviously I have imported arcpy.)?

lyr = arcpy.mapping.Layer("<path>")
rlf = ("<path>")
arcpy.mapping.ExportReport(lyr, rlf, "<path>_detailedReport.pdf")

Apologies for remaining vague. I must repeat, this was working prior to the 10.2.1 update.
0 Kudos
MichaelMattaini1
New Contributor

Did you ever find a solution to this problem? I'm using 10.3 but getting the same thing:

Runtime error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "N:/13057/13057.3/Production/InspectionOnCall/Testing/PDF Generation Testing.py", line 14, in <module>
    generateReports("VPS-030")
  File "N:/13057/13057.3/Production/InspectionOnCall/Testing/PDF Generation Testing.py", line 12, in generateReports
    arcpy.mapping.ExportReport(inTable, template, "workOrder" + str(workOrderID) + ".pdf", "DEFINITION_QUERY", "Baltimore County DPW Bureau of Utilies On-call Contract Management", report_definition_query="SELECT * FROM tbl_Asset_Tracking WHERE WorkOrder = " + str(workOrderID))
  File "c:\program files\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files\arcgis\desktop10.3\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
0 Kudos
deleted-user-mezzanRtr2IZ
Deactivated User

Apologies upfront.  Being over a year ago, I can't recall exactly what was done to resolve this.  I did learn that ExportReport will not support background processing and it did not seems to like being a part of a stand alone Python script either.  I was able to execute this funtion by turning off background processing and running the script via a ArcMap Script Tool. 

0 Kudos
PatrickSeastar
Occasional Contributor

Thanks, this did the trick for me as well. Not sure though why this function works better within an ArcMap environment rather then running as a standalone script.

Thanks for the help.

0 Kudos
curtvprice
MVP Esteemed Contributor

lyr = arcpy.mapping.Layer("<path>")

arcpy.mapping.ExportReport(inTable, ...

Is <path> a table or feature class? If so this won't work, you need to create a layer object.

0 Kudos
deleted-user-mezzanRtr2IZ
Deactivated User

report_src in arcpy.ExportReport() can be reference to layer file or a table view. I am utilizing the former in this example.

0 Kudos