When it comes to Python, there are a multitude of ways that you can use it to make your workflows more efficient. From customizing models to automating processing to ArcGIS Notebooks; you can do it all with Python!
Still finding your bearings with Python? Not quite ready to tackle use cases? Check out our article on learning Python, Scripting With Snakes: A Beginner’s Guide to Python, before continuing on!
Customizing Models
Have workflows that you are constantly repeating or are time intensive? ModelBuilder is your place to start and creating custom tools is a great place to start with Python.
- Start by choosing a workflow that doesn’t require user input each time and build out the model for it.
- Once you have it built out, run it as a whole and as parts to verify that you are getting the expected outcome at each step. This will allow you to better troubleshoot later in your script if things fail.
- Now is the time to export the model to Python, here is the documentation for ArcGIS Pro and ArcMap.
- Take some time and explore what the script looks like, walk yourself through it step by step to understand how things are put together. You can compare it back to your model to understand the progression of things.
- Now is the time to start customizing! Add in print statements after each task to verify that each part is complete or add in statements to write to a log file. This will allow you to better trouble shoot if something fails in the process.
Automating the Process
Now that you’ve got your workflow into a model and back out to a Python script, try scheduling it! Using Windows Task Scheduler you can set your scripts to run after hours, on the weekend, or over your lunch break. This is a great option for daily, weekly, or monthly tasks; saving you time to work on other tasks that can;t run themselves.
The following steps correspond to the images in the above gallery. Together they will walk you through setting up a scheduled task for your python script.
- Create Task, here is where you choose the user to run the task (by default, the user setting up the task).
- If running the task outside of office hours, choose ‘run whether user is logged on or not’.
- Then set the ‘configure for’ section to choose the version of windows you are running on.
- Trigger, choose when you want the task to run and how often you want it to run.
- New Action, here is where you will fill in the path for the Python application and your script.
- New Action, now you are all set to hit the ‘ok’ button and let it run at the scheduled time.
- You may be prompted to put in your password if you chose to run the task after hours and the setting to ‘run whether user is logged on or not’.
Want a more in-depth walk through of the process? Esri has a great walk through on the process on scheduling a model or script!
Resources
When learning Python there are many paths you can take on the road to becoming a Python master. There is no wrong way to learn Python if you start with the basics and move at your own pace.
- Want more Python resources or possible use cases to help you learn? Check out Esri’s four-part blog, here is part one!
- Python Scripting for ArcGIS is a great text to have at your fingers if you are an experienced ArcGIS Desktop user learning Python.
- Looking for an update Python book to use with ArcGIS Pro? Keep an eye out for the new Esri Press release, Python Scripting for ArcGIS Pro, set to be out in early summer.
- Try out your Python skills with R Notebooks in ArcGIS Pro or customizing feature search in a web map.