I am using ArcGIS 10.1 Standard with Python 2.7. I am trying to loop through records in a feature class using a Search cursor and for each record, run a custom ArcGIS report. I have created the report layout file (rlf) and can make this work outside a loop. The problem I have run into when I try to run within the loop is that the Search Cursor works with feature classes while the ExportReport function works with layers. I've tried using the MakeFeatureLayer function to make the conversion from feature class to feature layer within the loop, but seem to be missing something in the arguments for MakeFeatureLayer. This is the code I have used successfully to create the one-off report.
import arcpy mxd = arcpy.mapping.MapDocument(r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Figures\MXD\AGOL\CreateReports.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers") fccrossings = arcpy.mapping.ListLayers(mxd, "", df) arcpy.mapping.ExportReport(fccrossings, r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Reports\ArcGIS_Report_Templates\Report_SCRField_v6.rlf", r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Reports\SCR\Test\Test.pdf", "SELECTED")
And this is what I have come to using the loop.
import arcpy fccrossings = r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Download_AGOL\NF\SCR_04Nov2015_ReducedPhotos\366c11ade3cb4b95a3772296a1b0d8f1.gdb\StreamCrossingNF" with arcpy.da.SearchCursor(fccrossings, ["OBJECTID"], '"OBJECTID" = 1337') as cursor: for row in cursor: report = arcpy.MakeFeatureLayer_management(row, "templayer") arcpy.mapping.ExportReport(report, r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Reports\ArcGIS_Report_Templates\Report_SCRField_v6.rlf", r"G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\StreamCrossingReports\Reports\SCR\Test\Test.pdf") del cursor
This is the error message I receive...
Traceback (most recent call last): File "G:\505573\MGT\40-ENG\4E-ENV\GIS\Misc\Python Scripts\CreateSCR_v2", line 7, in report = arcpy.MakeFeatureLayer_management(row, "templayer") File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer raise e RuntimeError: Object: Error in executing tool