Select to view content in your preferred language

Calculate Field Script runs but does nothing

933
6
12-14-2011 10:43 AM
RichardThurau
Deactivated User
Hi ESRI community,

I have a fairly straight forward script I'm trying to run from a Calculate Field tool in a model.

The objective is to populate Fee_Tier according to values in Fee_Class and Total_IA.

Input table is a feature class in a GDB.
Field Name: Fee_Tier
Expression: fee(!Fee_Tier!, !Fee_Class!, !Total_IA!)
Expression Type: PYTHON
Code Block:
def fee(FT, FC, TI):
  if FC == "SFR":
    if TI >= 99.5 and TI < 2000.5:
      FT = 1
    elif TI >= 2000.5 and TI < 2900.5:
      FT = 2
    elif TI >= 2900.5 and TI < 3900.5:
      FT = 3
    elif TI >= 3900.5 and TI <  7500.5:
      FT = 4
    elif TI >= 7500.5:
      FT = 5
    else:
      FT = NotImplemented
    return FT


The tool runs but Fee_Tier remains completely populated with NULL values.

I'm really tired today, so with any luck I'm just missing something easy.

Thanks!

Rich
Tags (2)
0 Kudos
6 Replies
RichardThurau
Deactivated User
Does a bunch of views and no replies mean that my code is so ridiculous no one cares to comment? Or is it people can't reproduce the problem or don't know what the solution is?
0 Kudos
MathewCoyle
Honored Contributor
Try an update cursor would be my only suggestion.
0 Kudos
RichardThurau
Deactivated User
Thanks Mathew. Try an update cursor because this code will never work, or just because you think it's better? Why do all the examples from ESRI demonstrate the script function like this?
BTW, there are no examples where multiple fields are used.

In theory, SHOULD THIS SCRIPT WORK?

RT
0 Kudos
RichardThurau
Deactivated User
:confused: Can an update cursor run from a model?

My task is to get a bunch of models to run the python code upgraded from VB. From what I have read, I think I am locked into the Field Calculator, therefore locked out of using update.cursor?
0 Kudos
MathewCoyle
Honored Contributor
I just have had a lot of problems using field calculators and models in general. I find straight scripting outside of Arc much more stable.
0 Kudos
RichardThurau
Deactivated User
For anyone in the same boat looking for an answer to this thread, the solution has been in using the "script tool" to bring scripts into a model as a tool. Not fully successful yet but seems very nice for having full python functionality inside modelbuilder.

Rich
0 Kudos