Select to view content in your preferred language

Run a notebook using model builder

1035
4
12-06-2023 07:05 AM
EmekaUde
Emerging Contributor

I am am quite new to writing python scripts using the notebook on ArcGIS pro. I have a script that runs perfectly and it is part of a larger analysis. For the full analysis I have built a model builder with several geoprocessing tools included.

I want to know how I can add this notebook script to be part of the model I'm building. As this model houses multiple analyses, I want tho have all the tools including the python script from the notebook run all at once by one click.

I really appreciate any suggestion on this.

0 Kudos
4 Replies
BobBooth1
Esri Contributor

I would suggest exporting the notebook to a .PY script file, and then in ArcGIS Pro, in a toolbox, configure a script tool to point to the script. One you have a script tool configured, you can add the script tool to your model, and it will be run when you run the model.

https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/a-quick-tour-of-creating-too...

 

This tutorial shows how to convert a Notebook to a PY script and configure it as a script tool:

https://learngis.maps.arcgis.com/home/item.html?id=24e13f2f4fe8453b9d1107e1f5b1d3cf

EmekaUde
Emerging Contributor

Thank you Bob, your response was really helpful. Is there a way I can force this script to run first before other tool in the model?

0 Kudos
BobBooth1
Esri Contributor

Emeka,

Yes, you can use a Precondition in Model Builder to determine which parts of disconnected processes run first.

https://pro.arcgis.com/en/pro-app/3.1/help/analysis/geoprocessing/modelbuilder/using-preconditions.h...

However, to make a precondition, you need to configure your script tool to have an output parameter.

https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/adding-a-script-tool.htm

You configure the output of the script tool to be the precondition for starting the next tool by connecting the output to the next tool as a precondition.

EmekaUde
Emerging Contributor

Thank you so much Bob. Your answers were really helpful.

0 Kudos