2

Code works on ArcMap "Field Calculator..." when I click on attribute and calculate.

But if does not work in ModelBuilder calculate field tool.

Any ideas?

Pre-Logic Script Code:

  def ifBlock(Country):
    if Country == 'China':
     return "A"
    elif Country == 'Canada':
     return "B"
    elif Country == 'Russia':
     return "C"

result=

   ifBlock(!Country!)
  • 1
    also, did you check your indentations (this is maybe just due to the layout, but indentations are not correct in your post – radouxju Aug 17 '17 at 8:29
  • Text field comparison to fill another (text) field. error I get is "ERROR 000539: SyntaxError: invalid syntax (<expression>, line 1) Failed to execute (Calculate Field (3))." – Rafael Aug 17 '17 at 8:31
  • 1
    The code above looks fine. Make sure you've selected "PYTHON" as the expression type. – MacroZED Aug 17 '17 at 8:33
  • I know code is ok, cos its works in field calculator, but not in modelbuilder calculate field tool. I knew there are differences how modelbuilder responds, but this is annoying – Rafael Aug 17 '17 at 8:35
  • 1
    Could you add a screenshot showing your model and the settings of the Calculate Field tool? – BERA Aug 17 '17 at 9:18
1

found the problem. i had : behind my result, like this:

result=

    ifBlock(!Country!): <--

I have removed it and now it works fine, thanks all!!!

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.