So I'm relatively new to ArcGIS and ArcCatalog. I have created a field name of PROJECTID in a feature class in a Personal Geodatabase. The data type is TEXT. This will be a ten digit ID. The first five characters will be a acronym. The sixth character will be a digit that represents the type of feature. It will be a number. The last four characters will be numbers that should be incremented starting at 0001.
Example:
WATER-1-0001
Screen shot of the field:
So my question is how can I do this in ArcCatalog. I've seen some Python code that will autoincrement like the following:
rec=[OBJECTID]
def autoIncrement(a):
global rec
return "water" + str(a) + "-" + format(rec, '04d')
Again I'm a newbie when it comes to ArcGIS .
Now I am getting an error NameError name 'OBJECTID' is not defined.
Best Answer
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
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
if your number has to depend on the type, it then makes sense to use the Python code block