I need to generate a unique id using field calculator in ArcMap. I am a student and I am having problems finding the script or getting auto increment to work or anything else.

  • if you have a geodatabase(no matter personal or SDE) you can use ArcToolBox and add GlobalId field to your table.It simply adds a unique id to your table.If you insist to use field calculator,you have to provide a code block in VB script or python for it.They don't have any ready to use function to generate unique id except you have a SDE SQL server database,in this case you can have a Guid field in your table and use NewId() (a function declared in SQL server) in field calculator(but not usable in personal geodatabase). – Reza Jul 6 '15 at 5:06

You'll need to create a quick python script to auto increment through values. In the field calculator, set the Parser to Python. Click Show Codeblock. In your Pre-Logic Script Code block, use:

def UID ():
 global i
  i += 1
  i = 1
  return i
  return str(i)

Then in your field calculator, just type:

UID ()


If you need to start over, click the Python window button on the Standard toolbar, and type del i. Start_Over

| improve this answer | |
  • you need just set i=0 or other value before def. del i isn't necessary – GeoStoneMarten Sep 25 '17 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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