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.
What am I doing wrong here?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI 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.
What am I doing wrong here?
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:
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?).
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.