1

This question already has an answer here:

I'm using the Field Calculator in ArcMap and I need to create a unique ID for every storm drain in my county. An ID Should look something like this: 16-I-003

The first number is the municipal number which is in the column/field titled "Munic"

The letter is using the letter in the column/field titled "Point"

The last number is simply just 1 to however many drains there are in a municipality.

So far I have:

rec=0
def autoIncrement()
pStart=1
pInterval=1
 if(rec==0):
  rec=pStart
 else:
  rec=rec+pInterval
return "16-I-" '{0:03}'.format(rec)

So you can see that I have manually been typing in the municipal number, the letter, and the hyphens. But I would like to pull the first number and letter from the fields: Munic and Point so I don't have to manually type them in each time it changes. I was hoping I could just put !Munic! and !Point! in my return statement before the .format(rec) or somehow work it in there.

I'm a beginner when it comes to python and ArcMap, so please dumb things down a little. The simpler the better!

marked as duplicate by Paul, Chad Cooper, Jason Scheirer, Chris W, Mapperz Jun 26 '14 at 20:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

I am unclear about your function's logic, but I would approach it like this...

Expression:

autoIncrement(!Munic!, !Point!)

Expression Type:

PYTHON_9.3

Code Block:

rec = 0
def autoIncrement(munic, point)
  pStart=1
  pInterval=1
  if(rec==0):
    rec=pStart
  else:
    rec=rec+pInterval
  return '{0}' "-" '{1}' "-" '{2:03}'.format(munic, point, rec)  

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