I want to calculate the value of a new field using an if-else condition with field calculator in modelbuilder. Want I want to do is as follows: if my new field is empty, then use the expression entered by the user to calculate the value of the field; else do nothing and keep it as it is.

What I have done so far is the following:

Field Calculator

  • Try changing the OR CODE VALUE with %OR CODE VALUE%; it will be best if both within the model and the script you add some underscores: OR_CODE_VALUE – dof1985 Apr 8 '15 at 12:55

I wouldn't use the function name 'Reclass', I think that may already be the name of an existing function.

But basically, 'OR CODE Value" is not correct. It's not clear exactly what you want to do. It looks like you just want to return the same value you're passing in. You're returning the existing OR_CODE value when OR_CODE is an empty string, and it looks like you want to return the existing OR_CODE value value when it's not. So it looks like you just want to calculate the same value as already exists either way, which seems kind of pointless. Maybe what you want is to return some different value when OR_CODE = '', otherwise keep the existing value. Try something like this:

def rcls(someCode, otherValue):
    if someCode == '':
        return otherValue   # or, calculate a value
        return someCode

OR_CODE = rcls(!OR_CODE!, 'someOtherValue')
  • I think they were refering to a model varible, which should look something like this %variable_name% – dof1985 Apr 8 '15 at 12:56
  • Ah, ok, not real familiar with Model Builder. Main problem seems to be the logic though, or at least I'm unclear as to what the OP is trying to do. – recurvata Apr 8 '15 at 13:27
  • Thanks recurvata, it´s exactly what I wanted to do and it worked. I'm fairly newish with modelbuilder. – AtlantisNaranja Apr 12 '15 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.