Hey guys,
I working to get a report to run from a script and I can not figure out what I'm doing wrong. Any help you would have would be great. Thanks!
import arcpy
mxd = arcpy.mapping.MapDocument(r"G:\Public\Storm Projects\NPDES II Permit\Detention Basin Inspections\NEW_Detention Basins.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListTableViews(mxd, "ArcGISSDE.SDE.Detention_Basin_Inspection", df)[0]
arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", "[Date]= '12/1/2015'")
print ('Test')
arcpy.mapping.ExportReport(lyr,
r"M:\BrianLomas\RelationShipClassTest\DetentionBasin1.rlf",
r"C:\Users\blomas\Desktop\ReportTest.pdf",
"SELECTED")
del mxd
I currently get this error...
Executing: Report
Start Time: Mon Feb 27 13:47:32 2017
Running script Report...
Failed script Report...
Traceback (most recent call last):
File "M:\BrianLomas\Python Scripts\ImportantScripts\SelectReport.py", line 10, in <module>
"SELECTED")
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 532, in ExportReport
return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True))
IOError: Could not write output file from report
Failed to execute (Report).
Failed at Mon Feb 27 13:47:34 2017 (Elapsed Time: 1.90 seconds)
Solved! Go to Solution.
So, I finally got this bad boy to work. Thanks to both of you guys. Below is the script that worked but I had to run it as a python script with no parameters and in the foreground. On to figuring out the next few steps. Thanks again.
import arcpy
mxd = arcpy.mapping.MapDocument(r"G:\Public\Storm Projects\NPDES II Permit\Detention Basin Inspections\NEW_Detention Basins.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.TableView ("ArcGISSDE.SDE.Detention_Basin_Inspection")
arcpy.mapping.ExportReport(lyr,
r"M:\BrianLomas\RelationShipClassTest\DetentionBasin1.rlf",
r"C:\Users\blomas\Desktop\ProjectReport.pdf")
del mxd
Is the "ArcGIDSDE.SDE.Detention_Basic_Inspection" a single layer in the MXD?
yes, it's actually a related table if that makes a difference.
Is there a reason you're using "SUBSET_SELECTION" selection method on that table? Does the user select records prior to running this tool?
Also, I would make that layer a single variable in the tool. Right now the variable 'lyr' is assigned to an arcpy function of ListTableViews.
I'm trying to get it to just output a few pages because I haven't been able to get it to output anything. So, I was wondering if maybe it was an "out of memory" issue I was getting when I ran it from view\run report in arcmap. I was hoping to eventually build a script I can run on a handful of pages at a time because of the memory issue.
Right now, the selection is built into the script...
....
"SUBSET_SELECTION", "[Date]= '12/1/2015'")
Can you duplicate that selection in the Python GUI in that MXD without error?
Perhaps related to 32-bit/64-bit issue?
Yea, I wondered that. I added that script to a toolbox and ran it from there as suggested but I get the same error.
So, I finally got this bad boy to work. Thanks to both of you guys. Below is the script that worked but I had to run it as a python script with no parameters and in the foreground. On to figuring out the next few steps. Thanks again.
import arcpy
mxd = arcpy.mapping.MapDocument(r"G:\Public\Storm Projects\NPDES II Permit\Detention Basin Inspections\NEW_Detention Basins.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.TableView ("ArcGISSDE.SDE.Detention_Basin_Inspection")
arcpy.mapping.ExportReport(lyr,
r"M:\BrianLomas\RelationShipClassTest\DetentionBasin1.rlf",
r"C:\Users\blomas\Desktop\ProjectReport.pdf")
del mxd