Using a Python Script Tool in Modelbuilder

2634
7
03-06-2020 07:44 AM
JohnBrand
New Contributor III

I'm running ArcPro 2.2.

I wrote a small Python script and saved it as a Python Script Tool in my Toolbox.  It has no parameters.

I want to use it in in Model Builder in one of my existing models and I'm having trouble.  All I want to do is make sure that the script runs first before the rest of the model.  How do I make my script a precondition for the rest of the model?

Thanks

0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
0 Kudos
JohnBrand
New Contributor III

I want to make it a precondition.  Not sure how.  It won't allow me to connect it to anything else in the model.

0 Kudos
DanPatterson_Retired
MVP Emeritus

sounds like you can make one of your inputs the precondition

0 Kudos
JohnBrand
New Contributor III

I don't follow.

My script (circled in green) downloads a zip file, unzips it, and overwrites existing data on my network.  How do I make the newly downloaded data a precondition to execute the model?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Make the folder where your zip is located a parameter, even if you provide defaults, since I can only assume that your next two inputs come from there.  that won't necessarily work since the zip may take more time that you need to use it as an input to something else.  You could alternately add another boolean parameter to your script... "continue" and check for its value after the download and unzip in your script.  You could even add a time.sleep to delay completion of the script to allow for unzip

0 Kudos
JohnBrand
New Contributor III

Like this?

Setting the Default to the folder where the data is saved & extracted?

0 Kudos
robertkalasek
New Contributor III

@JohnBrand

similar problem here - and i didn't get the point of your last message. i have a script that chanes Null-Values in a table into zeros and i have put that script into a script-tool-node. since the script doesn't return any output i am not able to use the node as a precondition for the following "calculate field" node. adding a parameter with the default path - as you supposed - doesn't change my situation - since this input parameter can't be used as a precondition for the field calculator node as well. so i think i would need a return value within the script, use that value as an (output-)parameter, use that parameter as a variable within my model, and somehow check that variable value as a condition for going into the calculation step of my "Calculate Field"-node. but i have no idea how to implement that ... thx for help

 

0 Kudos