Select to view content in your preferred language

How do I convert my python script to a tool in model builder?

934
2
08-07-2017 06:03 AM
AndrewMartin8
Deactivated User

There are multiple inputs in my code and I was wondering how I can have those inputs made within model builder. I am going to have many outputs so I am not interested in adding a code that makes an output block in the model builder, just inputs. For example, the code below. I want to write a code that would replace Flowaccumulation and Flowdirection as my inputs in the code because its just reading a file that I told it to. I want to replace it with code that I can manually put inputs in them through model builder. Please show me a code and not just a link. Thank you.

import arcpy
from arcpy.sa import *
from arcpy import env

Flowaccumulation="rC:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_fa"
Flowdirection= "rC:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_fd" 
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

GetParameter as text

Then if using a tool in a toolbox with the script as the calling script, make sure that you assign the inputs as the correct type

Flowaccumulation = arcpy.GetParameterAsText(0) 
Flowdirection = arcpy.GetParameterAsText(1)





KevinDunlop
Frequent Contributor

You need to use the GetParameterAsText method.  Remember that you need to keep the proper index order for your inputs.

Flowaccumulation= arcpy.GetParameterAsText(0)
Flowdirection= arcpy.GetParameterAsText(1)