you need to use this code within ArcMap and the field calculator. Add your feature class in the table of content, right click on it to open the table, right click on the name of the field and launch the field calculator.
Then you check for codeblock and copy the code you mentioned.
now for your code snippets, here is what I would do
rec=0
def autoIncrement(a):
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec += pInterval
return "water" + str(a) + "-" + format(rec, '04d')
you call this code using
autoIncrement(!name_of_field!)
where name_of_field contains the type of feature
EDIT : If you want to use the OBJECTID field directly, then a simple concatenation is enough
"WATER-" + str(!typrfield!) + "-" + format(!OBJECTID!, '04d')
if your number has to depend on the type, it then makes sense to use the Python code block
rec1=0
rec2=0
def autoIncrement(a):
global rec1
global rec2
pStart = 1
pInterval = 1
if (a == 1):
if (rec1 == 0):
rec1 = pStart
else:
rec1 += pInterval
out = "water-1-" + format(rec1, '04d')
else:
if (rec2 == 0):
rec2 = pStart
else:
rec1 += pInterval
out = "water-2-" + format(rec2, '04d')
return out
Best Answer
you should rather change the display so that you don't duplicate your field.
1) Open your attribute table
2) right click on the name of your field
3) select "properties"
4) Press the icon next to "numeric"
5) select percentage : the number represent a fraction
6) go to the option for rounding (number of decimal places set to 0 )