4

Scenario:

I have four fields: A, B, C and D

Field A is text-based and contains values from '000' up to some number 'xxx' Field B contains a set of values (also text, but represented by numbers) Field C contains a set of values (also text, but represented by numbers) Field D is empty and waiting to be populated

I would like to construct an if-then statement in Field Calculator that does something like this:

If Field A = 000 then Field D = Field B, 
If Field A =/= 000 then Field D = Field C

I have spent the better part of my day trying to find the proper 'language' to ask Field Calculator, but I'm stuck. I have 0 programming experience also.

Could anybody show me how this should be set up either in Python?

I'm using ArcGIS 10.0.

8

Using Python, the calculation would look like this:

For the Pre-Logic Script:

def Calc(a,b,c):
 if a == "000":
      return b
 else:
      return c

For the expression:

Calc( !A! , !B! , !C! )
  • Hi Thanks for the reply! I was not able to get this script to work....should it be used in Python or Python_9.3? Also when I go to insert the real names of my fields, they always have the exclaimation points before/after. Should they also appear that way in the Pre-logic script? – user24272 Nov 22 '13 at 18:47
  • In the pre-logic, the variable names are simply placeholders and can be called whatever you like. – nmpeterson Nov 23 '13 at 15:55
  • Wow - ok thanks nmpeterson for pointing that out. Totally worked! Many, many thanks! – user24272 Nov 25 '13 at 16:20
1

Pythonic inline if is working in Field Calculator expression

res=(on_false, on_true)[condition]

arcpy.CalculateField_management("fc" , "field" ,"(!C!, !B!)[!A!=='000']" , "PYTHON_9.3")
  • Thank you for the response! I was able to -briefly- get your post to work, but when I tried to integrate the script into a larger model it broke down and keeps giving me this error: ERROR 000539: Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000732: Input Table: Dataset PARCEL does not exist or is not supported Failed to execute (Calculate Field). Any ideas what might be happening? – user24272 Nov 22 '13 at 18:42
  • Input Table: Dataset PARCEL does not exist or is not supported Failed to execute (Calculate Field) this error means , i think that the feature class has not been found. – geogeek Nov 22 '13 at 19:31

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.