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!)
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Aug 17, 2017 at 8:18
7
  • 1
    also, did you check your indentations (this is maybe just due to the layout, but indentations are not correct in your post Commented Aug 17, 2017 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))." Commented Aug 17, 2017 at 8:31
  • 1
    The code above looks fine. Make sure you've selected "PYTHON" as the expression type. Commented Aug 17, 2017 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 Commented Aug 17, 2017 at 8:35
  • 1
    Could you add a screenshot showing your model and the settings of the Calculate Field tool? Commented Aug 17, 2017 at 9:18

1 Answer 1

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!!!

answered Aug 17, 2017 at 12:54

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.