Hello All,
We have a cool little geoprocessing analysis script that creates some data, does a bit of analysis and generates an awesome pdf 😉 .... this script works great when run from a desktop toolbox. When we publish it to server to connect to a web application, it fails at the point where we open the layout (pagx). There's no error message, the job just seems to die. Nothing in the AGS logs after a certain point when setting log level = debug. All the data and analysis artifacts (charts, csvs) get created fine -- i can inspect them in the AGS jobs folder. It's definitely in the final manipulation and export of the layout.
We've done this before with ArcMap mxds and this is the first attempt with Pro aprx/pagx so maybe I'm just missing a crucial step in the process of opening the layout.
I've distilled out all the fun data analysis and made a simple layout with a single text element for the title and a single map with only the stock basemap... no custom data, no fancy other elements... still dies in the same manner.
I took out the map, so the layout has only a text element which the script/service will modify when run to ensure something is running dynamically and it works. So it seems like something with the map/map frame is the issue. Is there a 'activate' or 'update' map needed?
Setup: ArcPro 2.9.5 / ArcGIS Server (standalone) 10.9.1
Here's the guts of the "run" method in the simplified script. Any thoughts would be greatly appreciated
def ScriptTool(input_templates_folder, input_cool_text):
analysis_folder = arcpy.env.scratchFolder
map_template = os.path.join(input_templates_folder, 'Layout3.pagx')
arcpy.AddMessage('Template PAGX: {}'.format(map_template))
analysis_template = os.path.join(analysis_folder,'Layout3.pagx' )
arcpy.AddMessage('Analysis PAGX: {}'.format(analysis_template))
shutil.copyfile(map_template, analysis_template)
arcpy.AddMessage('Analysis PAGX: copied')
lyt = arcpy.mp.ConvertLayoutFileToLayout(analysis_template)
arcpy.AddMessage('Analysis PAGX: opened')
txt = lyt.listElements('TEXT_ELEMENT', 'Text')[0]
arcpy.AddMessage('Analysis PAGX: element found')
txt.text = input_cool_text
arcpy.AddMessage('Analysis PAGX: element updated')
layout_pdf = os.path.join(analysis_folder, "layout.pdf")
arcpy.AddMessage('Analysis PAGX: exporting to {}'.format(layout_pdf))
lyt.exportToPDF(layout_pdf)
arcpy.AddMessage('Analysis PAGX: complete')
return layout_pdf