run arcpy on server

1154
10
Jump to solution
03-23-2021 07:04 AM
NatashaManzuiga
Occasional Contributor

Hi everybody, is it possible to run an arcpy scripts with:

  • ArcGISProject that open .aprx file
  • arcpy.da.SearchCursor to connect to oracle
  • exportToPDF to export a Layout in the .aprx

and if yes,  is it possible to schedule it or run it on demand?

Thanks,

Naty

 

Tags (1)
0 Kudos
2 Solutions

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Looking to Esri's documentation on Authoring geoprocessing services with Python scripts—ArcGIS Pro | Documentation:

Most Python script tools that execute successfully on your computer will publish and execute successfully as a geoprocessing service—you do not have to modify your script in any way.

In terms of scheduling, there are multiple ways it can be done, which works best depends on your situation.  Geoprocessing services themselves do not have a setting to have the service execute automatically, the service has to be called.  ArcGIS Pro includes scheduling tools, which rely on Windows Task Scheduler, and Notebook Server now supports scheduling notebook tasks. 

View solution in original post

UriGilad_EsriAu
Esri Contributor

Hi @NatashaManzuiga,

Yes, it's possible to run such a script. 

Get the .aprx file:
aprx = arcpy.mp.ArcGISProject(path to aprx)
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm

Define source:
Source = path to feature class on sde on Oracle

Search cursor
cursor = arcpy.da.SearchCursor(source, [fields to seach])
https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm

Get the layout from the .aprx
layout = aprx.listLayouts("wildcard layout name*")[0]
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layout-class.htm

Export to PDF:
layout.exportToPDF(path of output file)
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/pdf-export.htm

As for scheduling, @JoshuaBixby has it right - it'll depend on your platform, but yes, it's possible.

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

View solution in original post

10 Replies
JoshuaBixby
MVP Esteemed Contributor

Looking to Esri's documentation on Authoring geoprocessing services with Python scripts—ArcGIS Pro | Documentation:

Most Python script tools that execute successfully on your computer will publish and execute successfully as a geoprocessing service—you do not have to modify your script in any way.

In terms of scheduling, there are multiple ways it can be done, which works best depends on your situation.  Geoprocessing services themselves do not have a setting to have the service execute automatically, the service has to be called.  ArcGIS Pro includes scheduling tools, which rely on Windows Task Scheduler, and Notebook Server now supports scheduling notebook tasks. 

NatashaManzuiga
Occasional Contributor

I run the script with 3 parameters...and it's ok in local.

projectPath=arcpy.GetParameterAsText(0)
dbTablePath=arcpy.GetParameterAsText(1)
pdfPath=arcpy.GetParameterAsText(2)


I'trying to publish the script but how can I change the parameters (to let it run on the server) ?

and also I tried to publish a simple script...with:
print ("Hello")

and I got this error:
Script1 113 GPService https://xxxxxxxx:6443/arcgis/admin siteadmin 2021-03-24 16:33:26 Status: Failed StatusMessage: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. ErrorMessage: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.

 

 

Thanks, Naty

0 Kudos
UriGilad_EsriAu
Esri Contributor

Hi @NatashaManzuiga,

Yes, it's possible to run such a script. 

Get the .aprx file:
aprx = arcpy.mp.ArcGISProject(path to aprx)
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm

Define source:
Source = path to feature class on sde on Oracle

Search cursor
cursor = arcpy.da.SearchCursor(source, [fields to seach])
https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm

Get the layout from the .aprx
layout = aprx.listLayouts("wildcard layout name*")[0]
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layout-class.htm

Export to PDF:
layout.exportToPDF(path of output file)
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/pdf-export.htm

As for scheduling, @JoshuaBixby has it right - it'll depend on your platform, but yes, it's possible.

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

NatashaManzuiga
Occasional Contributor

I run the script with 3 parameters...and it's ok in local.

projectPath=arcpy.GetParameterAsText(0)
dbTablePath=arcpy.GetParameterAsText(1)
pdfPath=arcpy.GetParameterAsText(2)


I'trying to publish the script but how can I change the parameters (to let it run on the server) ?

and also I tried to publish a simple script...with:
print ("Hello")

and I got this error:
Script1 113 GPService https://xxxxxxxx:6443/arcgis/admin siteadmin 2021-03-24 16:33:26 Status: Failed StatusMessage: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. ErrorMessage: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.

 

 

Thanks, Naty

 

0 Kudos
UriGilad_EsriAu
Esri Contributor

Hi Naty, would you be able to share the script/toolbox?

0 Kudos
NatashaManzuiga
Occasional Contributor

I just want to run it on my Linux ArcGIS Server. What I have to do?
Thanks,

Naty

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Please share the simple script with the print statement in it that fails (unless the script it just the one line you already shared), then others can look at the code and try publishing it on their machines to see if there are issues. 

0 Kudos
NatashaManzuiga
Occasional Contributor

here you are :)

print("Hello World")

@JoshuaBixby wrote:

Please share the simple script with the print statement in it that fails (unless the script it just the one line you already shared), then others can look at the code and try publishing it on their machines to see if there are issues. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you can't successfully publish and execute your single-line script, then something is definitely configured wrong with ArcGIS Server.  Unfortunately, ERROR 999999 is a catch-all error code when something more specific isn't available.  I suggest contacting Esri Support at this point because it is hard for Esri Community members to troubleshoot issues with users' ArcGIS Enterprise deployments.

0 Kudos