5

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)

In response to the suggestions below, I've tried the following with full paths, but am receiving the same error.

>>> arcpy.mapping.ExportReport('2013pp',r"C:\reports\Graffiti.rlf", r"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'>

When I try Blord's suggestion I get the following:

>>> arcpy.mapping.ExportReport(arcpy.mapping.Layer('2013pp.lyr'),"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\arcobjects\mixins.py", line 389, in __init__
    super(LayerMixin, self).__init__(lyrfile)
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 47, in __init__
    for arg in args))
ValueError: Object: CreateObject Layer invalid data source
>>> 

The last part about the invalid data source makes me wonder about whether the shape file is acceptable...it should be given that I am able to manually create a report with it.

As an aside, is this only an arcpy mapping tool, i.e. I can't find it in ModelBuilder or in a toolbox?

I was hoping to try to trouble shoot by creating the tool in ModelBuilder, exporting it and examining the script.

1

2 Answers 2

5

mapping.py is running an assertion test to make sure that your report source is a MapDocument, TableView, or Layer. This is the first argument you provided.

And it is not a MapDocument, TableView, or Layer, it is a string. That is what AssertionError: <type 'str'> means.

Instead of giving the string '2013pp' you need a reference directly to 2013pp as a Layer object. Try:

arcpy.mapping.ExportReport(arcpy.mapping.Layer(u'C:\\project\\2013pp.lyr'),u'C:\\Py‌​thon\\reports\\2013_Graff‌​iti.rlf', u'C:\\report.pdf')

What I have done here is turn the string into a Layer object in the middle of the function arguments. Edit: Modified based on full path to .lyr file. Also converted all strings to unicode

6
  • I've edited the original post to indicate the results when I tried this, unfortunately: unsuccessful.
    – David Meek
    Apr 16, 2013 at 18:07
  • Try the full path to the .lyr file. Apr 16, 2013 at 19:07
  • still doesn't work with the full path to the layer file, gives same error as before arcpy.mapping.ExportReport("C:\project\2013pp.lyr","C:\\Python\reports\2013_Graffiti.rlf", "C:\report.pdf")
    – David Meek
    Apr 16, 2013 at 21:10
  • You left out the class creation with arcpy.mapping.Layer. Just to make sure it is not a raw versus unicode string problem too, try arcpy.mapping.ExportReport(arcpy.mapping.Layer(u'C:\\project\\2013pp.lyr'),u'C:\\Python\\reports\\2013_Graff‌​iti.rlf', u'C:\\report.pdf') I modified the answer above to reflect this version. Apr 16, 2013 at 21:15
  • I don't think so, as I got this error with that: Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: __init__() takes at most 2 arguments (4 given)
    – David Meek
    Apr 16, 2013 at 21:22
2

I think this might be a path issue, try example below.

e.g.

arcpy.mapping.ExportReport('2013pp',r"C:\reports\2013_Graffiti.rlf",r"C:\reports\2013_Graffiti_report.pdf")
1
  • I've edited the original post to indicate the results when I tried this, unfortunately: unsuccessful.
    – David Meek
    Apr 16, 2013 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.