AnsweredAssumed Answered

Obscure ExportToJPEG problem

Question asked by wroe on Apr 25, 2018
Latest reply on Mar 4, 2020 by flspat

Here's a strange one ... would love to hear some feedback. I managed to fix the problem but I don't understand why this was a problem in the first place. I believe this has to do with how I was passing a directory string into the tool.


We have a relatively simple arcpy script that exports jpegs to a folder. The script runs on a Windows 2008 R2 server where we have both ArcGIS Server 10.3.1 installed along with ArcGIS 10.3.1 desktop. Since the latter was the last installed, the default Python IDLE is 32-bit.


When the script is run interactively in IDLE, it runs just fine with no errors. However, when run via Windows Task Scheduler, it throws the error "PageLayoutObject: Error in executing ExportToJPEG". I am 100% positive that it is running from the same user account when we run it either interactively in IDLE or via Task Scheduler, and that that user account has the correct privileges to the writeoff directory.


The offending code is this:

arcpy.mapping.ExportToJPEG(mxd, r"R:\GIS\Maps\Map_" + str(pageName) + ".jpg", resolution = 250)


But when I make a relatively minor change, it works fine:

writeoff_dir = "//somedirectory/GIS/Maps/"

arcpy.mapping.ExportToJPEG(mxd, writeoff_dir + "Map_" + str(pageName) + ".jpg", resolution = 250)


Again, I must emphasize that both code snippets work fine when run interactively in IDLE; it's only when the first snipped is run in Task Scheduler that it throws an error. I tried pointing Task Scheduler to a batch file that referenced either the 32-bit and 64-bit IDLE versions installed on the machine, but it didn't make a difference.


So two questions for the community:

1. Why doesn't the input appear to like the 'r' prefix for the path?

2. Why would these both run fine interactively in IDLE but the first code snippet bomb via Task Scheduler?


Thanks in advance. At a minimum, I hope my solution helps someone experiencing the same uninformative error.