Select to view content in your preferred language

Route Solver - Add Locations - Convert Model Builder to Python script

247
5
3 weeks ago
ModernElectric
Frequent Contributor

Greetings:

I have created a manual process of creating a route within a File Geodatabase with the Add Locations and Solve geoprocessing tool, also building it into a model within ModelBuilder. However, the goal is to export the model to a stand-alone Python script to incorporate into an already established batch file. 

The issue I cannot solve is when I run the script outside of GIS, it keeps saying the path to the Network Analysis Layer does not exist. I also cannot figure out the proper path syntax for the route layer. 

Doing something wrong?

0 Kudos
5 Replies
MelindaMorang
Esri Regular Contributor

Usually converting models to scripts requires that you edit the scripts to adjust the file paths because you're switching from a context that interacts with the map in Pro to something that is intended to work in a standalone process.  But unless you can share the resulting script your model export created, it's not possible to diagnose the issue.

With that said, we don't recommend using network analysis layer workflows in Python.  For a faster and easier-to-use network analysis experience in Python, you should use the arcpy.nax module.  This documentation explains step by step how to do it: https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/performing-network-analysis.htm.

ModernElectric
Frequent Contributor

@MelindaMorang Is it possible to use the analysis tools for creating a route (Add Locations & Solve) in Model Builder, add the model to a ArcToolBox and use python outside of ArcGIS Pro and call the model to run? I tried doing that, but it kept throwing errors. 

0 Kudos
MelindaMorang
Esri Regular Contributor

Yes, you can call any model tool from Python.  You might get errors if the model has hard-coded data paths or is looking for layers in the map and it's being run outside of the map context.  You can make the inputs and output model parameters so your script can explicitly pass in the paths to the inputs and specify the output paths.

Here is a tutorial all about creating models for Network Analyst workflows, including some steps for configuring the model to run as a tool: https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/create-a-model-for-route-analysis.ht... 

If you continue to have problems, it is helpful, when you post a comment, if you paste the actual error you're getting.  Very helpful for diagnosing the problem!

ModernElectric
Frequent Contributor

@MelindaMorang 

I am trying to utilize the current license I have in ArcGIS Pro Advanced with a limited number of ArcTools available. From reviewing the help section, it appears what I am trying to do would require the Network Analyst extension license? 

0 Kudos
MelindaMorang
Esri Regular Contributor

If you're using a network dataset on your own system (one you created yourself or Streetmap Premium that you purchased from Esri), then you need the Network Analyst extension license.  If you're solving against the ArcGIS Online services, you don't need the extension license.

For questions about licensing and what tools and options you have available with your current licensing, your designated Esri representative is your best resource, so you should reach out to them. (If you're not sure who that person is or how to get in touch with them, feel free to send me a private message with your name and organization, and I can find out for you.)

0 Kudos