Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 model builder or in a toolbox? I was hoping to try to trouble shoot by creating the tool in model builder, exporting it and examining the script.

Any advice would be greatly appreciated, Best, David

share|improve this question
    
Yers, a shapefile will not work. A shapefile does not have the symbology information that a layer file does. I think that you can only do this tool with arcpy.mapping or the Report tools in the UI (resources.arcgis.com/en/help/main/10.1/index.html#//…) –  blord-castillo Apr 16 '13 at 21:12
add comment

2 Answers

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

share|improve this answer
    
I've edited the original post to indicate the results when I tried this, unfortunately: unsuccessful. –  David Meek Apr 16 '13 at 18:07
    
Try the full path to the .lyr file. –  blord-castillo Apr 16 '13 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_Graff‌​iti.rlf", "C:\report.pdf") –  David Meek Apr 16 '13 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:\\P‌​ython\\reports\\2013_Graff‌​iti.rlf', u'C:\\report.pdf') I modified the answer above to reflect this version. –  blord-castillo Apr 16 '13 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 '13 at 21:22
show 1 more comment

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")
share|improve this answer
    
I've edited the original post to indicate the results when I tried this, unfortunately: unsuccessful. –  David Meek Apr 16 '13 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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