arcpy.mapping.ExportReport: Error in generating report

977
12
02-19-2018 08:09 AM
OliverRaskop
New Contributor

Hello,

I am using ArcGIS 10.5 Basic.

I try to create an Report using Python. I always get an error. So finally I tried the Example 1 from the online-help (ExportReport—Help | ArcGIS Desktop :( I created a mxd with the File name C:\Project\Project.mxd, I created a Feature-Layer "Accidents" with some polygons. I created a report using VIEW > REPORTS > CREATE REPORT and saved it as "C:\Project\Project.rlf"

Finally I copied the code in a script  "C:\Users\or\Documents\ArcGIS\test1.py" and run.

This is the message:

Traceback (most recent call last):
  File "<string>", line 254, in run_nodebug
  File "C:\Users\or\Documents\ArcGIS\test1.py", line 8, in <module>
    "SELECTED")
  File "C:\WinApps\CAD-GIS\GIS\ArcGIS\Desktop10.5\ArcPy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "C:\WinApps\CAD-GIS\GIS\ArcGIS\Desktop10.5\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.

Any Idears?

Thanks,

Oliver

Tags (1)
0 Kudos
12 Replies
JoshuaBixby
MVP Esteemed Contributor

Although providing the error message, and especially the traceback, is helpful; it isn't always enough to provide meaningful suggestions.  What parameters did you pass to ExportReport and how are those defined?

0 Kudos
OliverRaskop
New Contributor

Thanks for your reply.

I used exactly the example from the online Help which is:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Accidents", df)[0]
arcpy.mapping.ExportReport(lyr,
                           r"C:\Project\Project.rlf",
                           r"C:\Project\Output\ProjectReport.pdf",
                           "EXTENT",
                           extent=df.extent)
del mxd

To do so I created all necessarily Data to match the script:

- Create a path in c:\Project

- create a new Project.mxd

- rename the "Layers"-Dataframe to "Transportation"

- create a FC and Layer "Accidents" (located in the default-fGDB: C:\Users\or\Documents\ArcGIS\Default.gdb) with three polygons.

- create a Project.rlf file from Layer "Accidents" by using VIEWS>REPORTS>CREATE REPORTS (Report Fields: ObjectID, Shape_length, Shape_Area; all other settings: default)

Hope this helps.

Oliver

0 Kudos
XanderBakker
Esri Esteemed Contributor

It seems that you copied the exact same code as used in Example 1 on the help page ExportReport—Help | ArcGIS Desktop . Since the error occurs on line 8 using the "EXTENT" parameter, apparently you have an mxd, a data frame and a layer with the same name as used in the example. 

My first suggestion would have been to used named parameters, like this:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Accidents", df)[0]

arcpy.mapping.ExportReport(report_source=lyr,
                           report_layout_file=r"C:\Project\Project.rlf",
                           output_file=r"C:\Project\Output\ProjectReport.pdf",
                           dataset_option="EXTENT",
                           extent=df.extent)
del mxd

... but since the help page shows you can do this, it shouldn't be the problem. Could it be data related? Can you share the mxd, report and data to see what the problem is?

0 Kudos
OliverRaskop
New Contributor

In the "project.zip" you find the mxd, the data (accidents-shape), the report and the script.

As you see I followed your suggestion with the named parameters but without success.

I also tried a point-shapefile instead of a polygon-FC (default.gdb) - same result.

It would be appreciated, if you could have a look into my data.

Thank you.

Oliver

0 Kudos
XanderBakker
Esri Esteemed Contributor

I just downloaded your ZIP and extracted it to C:\Project and changed the output name of the PDF and it ran without any problems. I'm using 10.6 (advanced license).

See PDF attached. 

I do notice from your error message that you didn't install ArcGIS in the default path. Any specific reason to do that? What other things have you changed during installation?

0 Kudos
OliverRaskop
New Contributor

Today I updated to 10.6. No change. (Win 10 Ver.1709)

I am using basic licence. But this should not make a difference because I am able to create the report using VIEWS>REPORTS>CREATE REPORTS.

I am also using "Background Geoprocessing (64-bit)".

The installation-Path is set by company guideline (also installation-path of python) - this is not my idea, but we never had problems with that.

I didn't change anything else during installation.

0 Kudos
OliverRaskop
New Contributor

It seems I found the solution:

I always run the script from the IDLE. If I run it by a tool (without parameters) from the toolbox it does not fail.

Thank you for your help. You put me on the right path...

0 Kudos
XanderBakker
Esri Esteemed Contributor

I ran the script as stand alone script using PyScripter and that worked too. You may also want to test with the background processing switched off. It should be possible to run the script from IDLE, or as stand alone script, from the Python window and as a tool.

0 Kudos
OliverRaskop
New Contributor

I ran the script from PyScripter, Idle, command prompt: no success

I ran the script with and without background processing switched on: no difference

I ran the script from PyScripter with or without ArcMap running: no difference

I ran the script from the Toolbox and from a python window in ArcMap: successful!

I ran the script from the Toolbox and from a python window in project.mxd or with a new ArcGIS-project open: no difference (in both cases successful).

I ran the script with or without "dataset_option": no difference

I modified the script for for debugging:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Accidents", df)[0]

outPDF =r"C:\Project\Output\ProjectReport.pdf"
RLFfile =r"C:\Project\Project.rlf"

try:
   print(lyr)
   print(outPDF)
   print(RLFfile)
   print("start try")

   arcpy.mapping.ExportReport(report_source=lyr,

                                                report_layout_file=RLFfile,

                                                output_file=outPDF)

   print("end try")

finally:

   print("start finally")

   del mxd

The result (PyScripter) is:

Accidents
C:\Project\Output\ProjectReport.pdf
C:\Project\Project.rlf
start try
start finally
Traceback (most recent call last):
File "<string>", line 254, in run_nodebug
File "C:\Project\reportscript.py", line 15, in <module>
output_file = outPDF)
File "C:\WinApps\CAD-GIS\GIS\ArcGIS\Desktop10.6\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\WinApps\CAD-GIS\GIS\ArcGIS\Desktop10.6\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

The error-message does not give me any hints.

I'm stumped.

0 Kudos