Select to view content in your preferred language

Creating a report in model Builder

7484
2
Jump to solution
11-29-2012 12:21 PM
ShawnOliver
Deactivated User
I have created a model that produces a feature class file containing an attribute table with fields and records that I would like to export in report format. I have tried searching for a generate report tool to add to my model but no luck. Does anyone know how to automate report generation from attribute data using model builder?
0 Kudos
1 Solution

Accepted Solutions
JeffMoulds
Esri Contributor
There isnt a 'Generate Report' GP tool. However, you can work around this by writing a bit of Python code - but you need a .lyr file and .rlf file - a report layout file. The .rlf would have to already exist, i.e. it would have to be pre-authored with the fields you want in the report. Then you would use arcpy.mapping.ExportReport - which is available at 10.1.

For the sake of demonstration in the script below, I simulate a model outputting a feature class by creating a new feature class using CopyFeatures.

import arcpy  arcpy.CopyFeatures_management(r'C:\TemplateData.gdb\USA\states',                               r'C:\TemplateData.gdb\USA\states2')  # Make a feature layer out of the feature class arcpy.MakeFeatureLayer_management(r'C:\TemplateData.gdb\USA\states2','MyTempLayer')  # Save the feature layer to a .LYR file arcpy.SaveToLayerFile_management('MyTempLayer','C:/temp/MyLayer.lyr')  # ExportReport needs a layer in a map doc or a .LYR file lyr = arcpy.mapping.Layer('C:/temp/MyLayer.lyr')  # Export the report to a common format, such as PDF arcpy.mapping.ExportReport(lyr,                            r"C:\Temp\MyRLF.rlf",                            r"C:\Temp\ProjectReport.pdf")


Alternatively, you could export the feature class to a table (e.g. DBF) and then use third party Python libraries (like ReportLab) to export the table to a PDF report. Or create a report in the arcmap layout by moving and cloning text boxes - both of which can get complicated. There are a couple examples of this on resource center.

Otherwise, the reporting tools in UI would have to be used.

View solution in original post

2 Replies
ChrisPedrezuela
Frequent Contributor
youd probably have to create a separate script that creates a csv or txt file from a feature attribute\standalone table,then add it to your model.
0 Kudos
JeffMoulds
Esri Contributor
There isnt a 'Generate Report' GP tool. However, you can work around this by writing a bit of Python code - but you need a .lyr file and .rlf file - a report layout file. The .rlf would have to already exist, i.e. it would have to be pre-authored with the fields you want in the report. Then you would use arcpy.mapping.ExportReport - which is available at 10.1.

For the sake of demonstration in the script below, I simulate a model outputting a feature class by creating a new feature class using CopyFeatures.

import arcpy  arcpy.CopyFeatures_management(r'C:\TemplateData.gdb\USA\states',                               r'C:\TemplateData.gdb\USA\states2')  # Make a feature layer out of the feature class arcpy.MakeFeatureLayer_management(r'C:\TemplateData.gdb\USA\states2','MyTempLayer')  # Save the feature layer to a .LYR file arcpy.SaveToLayerFile_management('MyTempLayer','C:/temp/MyLayer.lyr')  # ExportReport needs a layer in a map doc or a .LYR file lyr = arcpy.mapping.Layer('C:/temp/MyLayer.lyr')  # Export the report to a common format, such as PDF arcpy.mapping.ExportReport(lyr,                            r"C:\Temp\MyRLF.rlf",                            r"C:\Temp\ProjectReport.pdf")


Alternatively, you could export the feature class to a table (e.g. DBF) and then use third party Python libraries (like ReportLab) to export the table to a PDF report. Or create a report in the arcmap layout by moving and cloning text boxes - both of which can get complicated. There are a couple examples of this on resource center.

Otherwise, the reporting tools in UI would have to be used.