I have a Field Calculator I am using with Python and I keep getting the above error. Below is the screenshot of my Field Calculator I am using.

enter image description here

What am I doing wrong here?

  • 1
    I didn't see this question before answering the other. Just not that it is "overkill" to use a code block in this particular case because you can write it in a single line. Uncheck the code block and enter "water" + str(!SubTypeCode!) + format(!OBJECTID!, '%01d') – radouxju May 8 '14 at 5:44
up vote 4 down vote accepted

You are confusing the scope when defining your function and its arguments in the pre-logic script. An actual field cannot be within the definition of the function in the pre-logic script. See screen shot of a working field calculator function:

ArcMap 10.1 Field Calculator with Pre-Logic Script Code, field to the left is the field that is being calculated (it does not have to be highlighted).

Notice how temp is defined as an argument in the pre-logic script code and keeps its name when used inside the function. Then in the JanClass = block I use the function and define which field values I want to use.

So in your case add another argument to your function, call it objectID, and then when you call your function in the box below feed it !OBJECTID!. Additionally I am fairly certain that OBJECTID cannot be used in field calculator operations. If you are trying to do an auto increment function refer to the answer given by adouxju on this question - (How to auto increment a field in a feature class?).

  • We must have answered at almost exactly the same time. I like the pictures so +1, it's what I said with pictures and a bit more depth. – Michael Stimson May 8 '14 at 0:04
  • Thanks for the Great answer on this James. Great details as well. – yams May 8 '14 at 15:49

Not sure what a is supposed to be, but let's say it's FacilityID. In your PROJECT= line (the expression line) you put autoIncrement(!FacilityID!,!OBJECTID!) and your code block is:

def autoIncrement(a,ID)
  return "water" + str(a) + format(ID,"%01d")

I hope that clears it up for you; there's a reference http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004s000000 but it's a lot of reading before you get to what you want.

  • Nice work, Cheers! – GeoSharp May 8 '14 at 0:08

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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