Hey all,
I'm having trouble getting python to export a report in ArcMap 10.3. This is what I try to run:
import arcpy
rlf = r"D:\tool\tool_dev\Tool_Report.rlf"
layer = r"D:\tool\Test_Layer.lyr"
out = r"D:\tool\report.pdf"
arcpy.mapping.ExportReport(layer, rlf, out)
This is the output:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
arcpy.mapping.ExportReport(layer, rlf, out)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\mapping.py", line 524, in ExportReport
assert isinstance(report_source, (MapDocument, TableView, Layer)), str(type(report_source))
AssertionError: <type 'str'>
I get the same AssertionError no matter if I try to do it by command line within ArcMap, from IDLE, a new toolbox, or opening it with C:\Program Files (x86)\PYTHON27\ArcGIS10.3\python.exe. Additionally, I've tried it with background processing both on and off
Any ideas?
Solved! Go to Solution.
Thing is though, there are only the 3 required parameters.
However, you were absolutely correct about going with the examples. After following them closely, I figured out what was going on - despite directly referencing a .lyr file as the lyr file input, it wanted me to declare it as a layer file:
lyr = arcpy.mapping.Layer("D:\tool\Test_Layer.lyr")
Then this worked:
arcpy.mapping.ExportReport(lyr, rlf, out)
Glad we got it figured out!
Were you able to use this script in an earlier version of ArcMap?
Nope, I haven't tried before. But given that each of the variables are pretty straight forward - a polygon layer with an attribute table, an rlf file that I've made myself, and a generic output PDF directory - and the limited inputs needed for the arcpy function, I can't figure out what I'm doing wrong
There are many parameters you have skipped, I would used named parameters if you aren't going to specify the defaults within your ExportReport statement. Examples are in the help files
http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/exportreport.htm
Thing is though, there are only the 3 required parameters.
However, you were absolutely correct about going with the examples. After following them closely, I figured out what was going on - despite directly referencing a .lyr file as the lyr file input, it wanted me to declare it as a layer file:
lyr = arcpy.mapping.Layer("D:\tool\Test_Layer.lyr")
Then this worked:
arcpy.mapping.ExportReport(lyr, rlf, out)
Glad we got it figured out!