So I feel like this should be really simple to do but I can't manage to get it working and reading around this forum and some Esri documentation, there seems to be different ways to do and I am starting to confuse myself with it all! I will say I am familar with Esri and Models, but not Python.
Basically I have a model which takes in some table data from SQL and does some analysis and exports into a shapefile. All the relevant data is fully referenced in the model, the data isn't being pulled from the TOC or anything. All I want to do is run this model on a schedule, via Windows Task Scheduler probably.
I firstly followed this documentation https://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/modelbuilder/scheduling-a-model-run.htm which has me creating a python script file and using the import toolbox function.
import arcpy
arcpy.ImportToolbox(r"C:\path\myToolbox.tbx", "tbxAlias")
arcpy.myModel_tbxAlias(r"c:\pathToInput\inputFolder", r"C:\pathToGdb\output.gdb")
I tried replacing the "C:\path\myToolbox.tbx"
with my toolbox location, and enter the alias as found in toolbox properites in the "tbxalias"
bit.
I wasn't sure about the bit underneath, is this where you say where the model is? I tried replacing 'mymodel_tbxalias'
bit with my model name and then the same tbx alias as the section before. But this didn't work. Not sure if I then need the next bit for input and output location, as the model itself references where the input and output data is already? Also I have multiple inputs of data being brought in... I just got a bit lost in it. Here is the code I attempted:
import arcpy
arcpy.ImportToolbox(r"\\middata\Data\ESRI GIS\ArcGIS Pro Users\Daniel Hardwick\DH Template Map\DH Template Map.tbx", "DH Template Map")
arcpy.COVID_Mutual_Aid_Model_DH Template Map()
So 'DH Template Map'
is the name of the toolbox, and when in properties the alias is 'DH Template Map'
also.
The second bit I have used the name of the model which is 'COVID_Mutual_Aid_Model'
, then once again used the toolbox alias afterwards (DH Template Map), which I think is what the guidance instructed. But this didn't work.
So I then decided to look around this forum and seen people creating scripts which mention code such as 'arcpy.env.overwriteOutput = True'
which I can't see mentioned in Esri documentation.
What should my script look like to simply run a model in a toolbox? Creating the task in scheduler I am fine with but just need this script to run!
1 Answer 1
The path to your toolbox has spaces in it, remove the spaces and then try the importToolbox method on your model. Adjust the name of your alias to not have spaces as well. I have had this issue importing toolboxes into the SDK for arcgis pro.
Explore related questions
See similar questions with these tags.
arcpy.myModel_tbxAlias()
so that "myModel" is the name of your model and "tbxAlias is the name of the alias you used when you imported the toolbox.ImportToolbox
exactly like you are. Then, use the intellisense to get the correct syntax, type:arcpy.TBXNAME
and it should find it, select it and run. Now that you have it, copy it to your script.()
at the end, its like a function call. But further to that, go back to your model and update both the TBX and the Label to have NO spaces.Close and re-open Pro and try it all again. Right now the spaces look to be tripping you up.import arcpy arcpy.ImportToolbox(r"filepath to model\ToolboxName.tbx", "tbxalias") arcpy.model label name_Toolbox name()
Thanks for the help guys. Dan