The goal is run a report via python script periodically via a scheduled task. If there is a better method for scheduling I am all ears, but the crux of my issue is getting the python script to run outside of ArcMap. It runs fine within ArcMap, but as a standalone script it throws errors. Below is my code and an image of what errors it giving me. Any help is much appreciated.
import arcpy import sys import traceback mxd = arcpy.mapping.MapDocument(r"C:\ESRITest\NewGeoReportingSystem\GeoReportingGC.mxd") try: df = arcpy.mapping.ListDataFrames(mxd)[0] for lyr in arcpy.mapping.ListLayers(mxd,"",df): if lyr.name == "Concerns": arcpy.mapping.ExportReport(lyr,r"C:\ESRITest\NewGeoReportingSystem\GRS_GeneralReport.rlf",r"C:\ESRITest\NewGeoReportingSystem\GeneralReport.pdf") except arcpy.ExecuteError: # Get the tool error messages msgs = arcpy.GetMessages(2) # Return tool error messages for use with a script tool arcpy.AddError(msgs) # Print tool error messages for use in Python/PythonWin print msgs except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" # Return python error messages for use in script tool or Python Window arcpy.AddError(pymsg) arcpy.AddError(msgs) # Print Python error messages for use in Python / Python Window print pymsg + "\n" print msgs finally: del mxd
Is it an indent issue (not sure if it's just the Geonet forum formatting or if it's how you have it in your code)? There doesn't appear to be a required indent after your if statement:
Change this
for lyr in arcpy.mapping.ListLayers(mxd,"",df): if lyr.name == "Concerns": arcpy.mapping.ExportReport(lyr,r"C:\ESRITest\NewGeoReportingSystem\GRS_GeneralReport.rlf",r"C:\ESRITest\NewGeoReportingSystem\GeneralReport.pdf")
To this
for lyr in arcpy.mapping.ListLayers(mxd,"",df): if lyr.name == "Concerns": arcpy.mapping.ExportReport(lyr,r"C:\ESRITest\NewGeoReportingSystem\GRS_GeneralReport.rlf",r"C:\ESRITest\NewGeoReportingSystem\GeneralReport.pdf")
Hi James,
I think it just how it came across in Geonet. I did have it indented. Any other thoughts?
include the mapping module?
import arcpy.mapping
Probably not the issue. Maybe have a look at this arcgis 10.1 - Has anybody used arcpy.mapping.ExportReport successfully on 64bit machine? - Geographi...
James,
I found that very same link, and was reading it over. That is the issue. 32-bit vs 64-bit. I solved it by just telling the task scheduler to fun the 32-bit version.
Thanks for your help.
David,
Have you seen Arcpy Export report error?Jeffrey May says:
I did learn that ExportReport will not support background processing and it did not seems to like being a part of a stand alone Python script either. I was able to execute this funtion by turning off background processing and running the script via a ArcMap Script Tool.
Doesn't seem to help your case since you want to launch a scheduled task... but just noting others have had similar issues.
Chris,
Actually it does help. I was digging and digging and I found what both you and James are talking about. It is a 32-bit vs 64-bit issue. What I did to solve the problem was just tell the scheduled task to use the 32-bit version as the program to launch, and pointed it to the .py file. It worked like a charm. Now if I can figure out how to make it use the 32-bit version from inside the script and do a few more things, I will be all set. Thanks both of you for your help, and pointing me in the right direction.
Does anyone know if this has been resolved? I need to use ExportReport in an mxd. I have been narrowing down reasons why it would fail (network drive, bad path strings, etc) and it just won't open the rlf.