Select to view content in your preferred language

ArcGIS Pro 3.0.1: How to run a python script by Windows “task scheduler”?

3578
13
08-31-2022 01:51 AM
JamalNUMAN
Legendary Contributor

ArcGIS Pro 3.0.1: How to run a python script by Windows “task scheduler”?

 

In the screenshot below, I wanted to run a python script that performs the buffer for a given feature class. I fill the “buffer.py” script in the “add argument” box but couldn’t figure out what to stick in the “Program/scrip” box

 

Clip_1142.jpgClip_1143.jpgClip_1144.jpg

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
13 Replies
MichaelVolz
Esteemed Contributor

Is L1 in P.gdb and your output buffer L1_buffer supposed to be created in Q.gdb?  If so, I don't see a reference to P.gdb for L1 in the standalone script.  The model might recognize L1 because you had it in the Pro project but the standalone script does not know this.

RhettZufelt
MVP Notable Contributor

In your map, you show L1 as coming from P.gdb in the datasource view so when you just refer to it as L1, Pro automatically makes a view layer called L1 for input (which when inside of Pro is P.gdb\L1).  You are setting a scratch workspace, but I still see nowhere that sets the actual path to the Q.gdb (even though I don't see L1 in there) or P.gdb database.  So, just using "L1" for input inside of Pro will be using the one from the P.dgb.  If ran outside of Pro, the script is not being told what input dataset to use.

Basically, if you run this as a stand alone script, you either need to specify the workspace/featureclass path that you want to use for input, or, use the arcpy.mp module to open the map, set map, dataframe, etc. then just using "L1" as your source layer will pick the one name L1 in the table of contents (from the P.gdb FGDB).  Otherwise, if stand alone, not inside of Pro, the script will not know what what dataset "L1" is.

Suspect if you replaced the line:

 

 

L1 = "L1" 
with
L1 = r"C:\Z7\P.gdb\L1" 

 

 

it will work both inside and outside of Pro.

R_

 

MichaelVolz
Esteemed Contributor

Jamal:

In your model I would browse to the input data instead of using the input data from inside Pro in the dropdown list.  I believe when you then export the model to python, it will provide the full path to the input L1 feature class.

JamalNUMAN
Legendary Contributor

Right. It works like a charm. Thank you guys for the help

 

I fixed the source workspace and allowed overwriting as per the code below.

 

 

-------------------------

# -*- coding: utf-8 -*-

"""

Generated by ArcGIS ModelBuilder on : 2022-09-02 06:56:18

"""

import arcpy

 

def Model():  # Buffer

 

    # To allow overwriting outputs change overwriteOutput option to True.

    arcpy.env.overwriteOutput = True

 

    # Model Environment settings

    with arcpy.EnvManager(scratchWorkspace=r"C:\Z7\Q.gdb", workspace=r"C:\Z7\P.gdb"):

        L1 = "L1"

 

        # Process: Buffer (Buffer) (analysis)

        L1_Buffer = "C:\\Z7\\Q.gdb\\L1_Buffer"

        arcpy.analysis.Buffer(in_features=L1, out_feature_class=L1_Buffer, buffer_distance_or_field="5 Meters", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field=[], method="PLANAR")

 

if __name__ == '__main__':

    Model()

 

---------------------------------------------

 

At the level of windows scheduler, I filled out the fllowing:

 

Program\script:

c:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe

 

Add Arguments

"c:\Z7\Buffer.py"

 

Clip_1188.jpgClip_1189.jpgClip_1190.jpgClip_1191.jpgClip_1192.jpg

 

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine