Select to view content in your preferred language

How does modelbuilder work with scripts?

3387
3
04-26-2010 02:57 PM
jimparsons
Occasional Contributor
I'm aware that from modelbuilder I can export my script to python and then get more programmatic control over stuff like file names and folder locations and whatnot.

So the method would be a) design script in modelbuilder, b) export script to py, c) tinker with python code.

But if I want to modify the model in step a do I have to reexport everything, and thus have to do more tinkering as per step c)? Or is there a way for modelbuilder and python to coexist?

MY specific example is to put the files from each run of my model into a separate folder. I will name that folder using python's import time module, so each folder will be unique. I don't think I can do that in modelbuilder, I think I have to do that from the script.

But once the script is made it's harder to go back and edit the model. Dyou see what I'm saying? So the question is can model builder call on bits of python script to create folder names, or is it either/or: model approach, or script approach?

Thanks
0 Kudos
3 Replies
jimparsons
Occasional Contributor
I'm being dumb. The real question is can I call a model from a python script, passing the model my desired output names and folders?

That way I can tweak the model in modelbuilder, but won't have to tweak the python code every time I change the model.
0 Kudos
MikeSteven
Regular Contributor
I'm pretty to new to scripting and model building but yeah I think you can do that. In the script you can call all of the tools in the predefined toolboxes so if you create a model you want to call from a script, the model will be saved in whatever toolbox you choose to save it in and you would call that model in the same way you would call the other tools.

Hope that helps.
Mike.
0 Kudos
DaleHoneycutt
Deactivated User
I'm being dumb. The real question is can I call a model from a python script, passing the model my desired output names and folders?

That way I can tweak the model in modelbuilder, but won't have to tweak the python code every time I change the model.


Absolutely!  Geoprocessing is designed so that you can call models from models, models from scripts, and scripts from models.  You just need an understanding of model parameters and how to add your custom toolbox in Python.

See:
A quick tour of creating tools with ModelBuilder
Adding toolboxes in Python
0 Kudos