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

08-07-2017 06:03 AM
New Contributor III

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 import *
from arcpy import env

Flowdirection= "rC:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_fd" 
0 Kudos
2 Replies
MVP Legendary Contributor

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)

Occasional Contributor III

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)