3

I have a model (ModelBuilder) and within I added a python script to calculate a field. My problem now is, that I don't know how to make the output appear in my model as it is the same as the input (only with the field calculated).

I imagine there is a very simple way, but I am new to ModelBuilder and python and just can't think of it?

Alternatively, I could also try using the field calculator, but I would prefer it this way.

And here is my script:

import arcpy
from arcpy import env
env.workspace = arcpy.GetParametersAsText(0) # the workspace
inLayer = arcpy.GetParameterAsText(1) # The shapefile
inField = arcpy.GetParameterAsText(2) # The column in attr table with Area
outField = arcpy.GetParameterAsText(3) # The column in attr table which should be calculated
# Create a list from area field and find min & max value
listing = []
rows = arcpy.SearchCursor(inLayer)
for row in rows:
 listing.append(row.getValue(inField))
del rows
listing.sort()
min = listing[0]
max = listing[-1]
# Calculate the normalized value
rows2 = arcpy.UpdateCursor(inLayer)
for row2 in rows2:
 row2.setValue(outField, (max - row2.getValue(inField))/(max - min))
 rows2.updateRow(row2)
del rows2
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 9, 2013 at 14:15

1 Answer 1

1

You'll want to add your script as a tool in a custom Toolbox, then add your script tool into your ModelBuilder process.

When you create your script tool, be sure to set the script tool parameters up so that you have the Type parameter set to "Derived" with the Direction parameter set to "Output".

answered Sep 9, 2013 at 20:05
4
  • Thanks for that answer. However, the problem is not fully solved. It seems to go in the right direction. However, I cannot use the Output as a new Input in modelbuilder - I guess because I have no output mentioned in my script. So my next question is how to change my script to make that work? Commented Sep 10, 2013 at 9:02
  • I found the missing piece: Commented Sep 10, 2013 at 9:44
  • Nothing had to be changed in the script. Only I had to set the Obtained from Parameter to Input. Then everything works as it should. So thanks again for the help! Commented Sep 10, 2013 at 9:47
  • Glad I could help, @oddpodm. If this resulted in the info you need, please click the little "checkmark" next to my answer to close this question. Thanks. Commented Sep 11, 2013 at 14:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.