i have created the following tool to add two fields in a table and do a calculation in order to put the tool to ModelBuilder.

For some reason when i am going to put it as an input in an another tool it doesn't appear.

I think i have done something wrong with 1. SetParameter and also 2. i haven't managed to save it as a feature class and it's only in memory.In addition i don't have a gdb or an mxd.

Also i set set parameter as an output feature class at tool's parameters but it didn't make any difference.

I am using ArcGIS 10.2.2, any suggestion?

 # Import system modules
import arcpy
from arcpy import env
arcpy.overwriteoutput = True

# Set environment settings
inWorkspace = arcpy.GetParameterAsText(0)
inFeature = arcpy.GetParameterAsText(1)
outFc = arcpy.SetParameterAsText(2, "")
env.workspace = inWorkspace

# Set local variables
fieldName1 = "bear_60"
fieldName13 = "distance"

# Execute AddField for 2 new fields
arcpy.AddField_management(inFeature, fieldName1, "DOUBLE", "", "", "", "", "NON_NULLABLE")
arcpy.AddField_management(inFeature, fieldName13, "DOUBLE", "", "", "", "", "NON_NULLABLE")

# Calculate Field bear_60
inTable = inFeature
fieldname = fieldName1
expression = "getCalc(!aspect!)"
codeblock = """def getCalc(aspect):
    if aspect > 300:
        bear_60 = (aspect + 60) - 360
        bear_60 = aspect + 60
    return bear_60"""
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldname, expression, "PYTHON_9.3", codeblock)

# Calculate Field distance
inTable = inFeature
fieldname = fieldName13
expression = "getCalc(!distance!)"
codeblock = """def getCalc(distance):
    return 10000"""
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldname, expression, "PYTHON_9.3", codeblock

1 Answer 1


It looks like you don't actually produce an output from your tool, only modify the input file. Although you have an argument for outFc you're not creating the output. Notice: all fields added and field calculations are performed on the input feature class.

If you change your outFc to:

outFc = arcpy.GetParameterAsText(2)

the user can specify an output path. Then you can make a copy of the input feature class using:


Then just use outFc for the adding/calculating fields:

inTable = outFc

This will leave the original file as-is but give you an output that you will be able to pass to your next step in the model builder.

For further reference see: http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000020000000


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.