Python Scripting Error Export Layout

528
4
11-09-2020 07:19 AM
ConnorBerry
New Contributor

Good morning! I am using ARCGIS Pro v2.3 to develop a web tool, part of which exports pdf to a created directory on our server. While the script runs perfectly in arcgis Pro, when I publish it as a web tool I receive OS Error: (path.) This error occurs on the line lyt.ExportToPDF (path.) The path is dynamic, in the sense that a new folder is created in the directory each time, and changes each time the script is run. Additionally, I am able to write other files to the path, just not the pdf. I have tried changing paths, taking away transparency on the maps themselves, creating the pdf document before the output, etc. I am just so lost on this and would love some help/ideas. It makes no sense to me as well because the script runs perfectly up until I publish it as a web tool. Thanks! 

Tags (4)
0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

Is the parent directory registered to the ArcGIS server, and is it an FQDN or drive mapped path?

Can you share the script?

0 Kudos
ConnorBerry
New Contributor

Yes, the parent directory is registered and I believe it is a drive mapped path (though I am fairly new in this area so am not entirely sure.) I am unable to share the full script, but here are the parts I can share were it errors at

output_workspace = arcpy.GetParameterAsText(0) #folder
geodatabase_name = arcpy.GetParameterAsText(1) #string
os.mkdir(output_workspace + '//' + geodatabase_name)
output_workspace = output_workspace + '//' + geodatabase_name

def create_new_constraints_pdf(output_workspace, geodatabase_name, output_geodatabase):
aprx = arcpy.mp.ArcGISProject(path to aprx) #aprx gets copied to web tool
arcpy.env.workspace = output_geodatabase
map = aprx.listMaps()[0]
constraints_lyr = output_workspace + '//' + 'constraints' + '.Lyrx'
lyrFile = arcpy.mp.LayerFile(constraints_lyr)
lyt = aprx.listLayouts()[0]
legend = lyt.listElements("LEGEND_ELEMENT")[0] #Calls Legend Element
legend.syncNewLayer = True #Makes all newly added layers appear in legend
map.addLayer(lyrFile, 'Top')
for lyr in map.listLayers(): #For statement will properly color layers on map
if lyr.isFeatureLayer:
sym = lyr.symbology
if hasattr(sym, 'renderer'):
if sym.renderer.type == 'SimpleRenderer':
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.classificationField = "total_score"
sym.renderer.breakCount = 5

lyr.symbology = sym
lyr = map.listLayers()[0]
lyr.transparency = 20 #Sets transparency to 20%
legend.syncLayerVisibility = True #Places all layers on map into legend
lyt.exportToPDF(output_workspace + '//' + 'transparent') #(Errors out here)
map.clearSelection()

0 Kudos
DavidPike
MVP Frequent Contributor

try an os.path.join instead of concatenation on

lyt.exportToPDF(output_workspace + '//' + 'transparent')

also are you missing the .pdf in the filename?

The syntax highlighter would make this much more readable to others.

0 Kudos
TanuHoque
Esri Regular Contributor

@ConnorBerry 

Quick question: what version of ArcGIS Server you are running your service?

0 Kudos