0

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!

arcpy type error

invlaid syntax arcpy intellisense

9
  • If your model is hardwired to look for specific datasets then yes you have parameters. I think to help people a screen shot of your model would be useful?
    – Hornbydd
    Mar 24, 2020 at 17:51
  • Please edit your post to include your own actual full Python code (not the example code yours was based on). It's hard to debug code that cannot be seen. In essence change 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. Mar 25, 2020 at 0:18
  • 1
    To make sure you've got the correct syntax on the Import and calling of the tool, do this: Within the Python window of ArcMap, do the 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.
    – KHibma
    Mar 25, 2020 at 10:55
  • 1
    You need to put () 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.
    – KHibma
    Mar 25, 2020 at 14:40
  • 1
    Ok update :) I have managed to get it working. I noticed in the actual model the 'label' was a silly name like model 22 or something, so when I was trying to find the COVID model (as it is named) in the intellisense, I couldn't see it. I updated the model and named it appropiately and now I can find it easily. The final code is below: import arcpy arcpy.ImportToolbox(r"filepath to model\ToolboxName.tbx", "tbxalias") arcpy.model label name_Toolbox name() Thanks for the help guys. Dan Mar 27, 2020 at 11:30

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.