ArcGIS Toolbox – Create Unique ID with ArcPy

Share Button

(If you’re using Firefox, then right click and Save Link As)
Download the Create Unique IDs Toolbox – works with ArcGIS 10.1+
View the Source Code

(any donations go towards hosting costs)

** Run this tool from ArcCatalog, and do not have the feature class / table opened anywhere else.

The Creates Unique IDs tool adds a field called UID and creates a unique ID for each record of an input feature class or table. The unique IDs can be grouped based on a common field attribute and also sorted in ascending or descending order. A prefix and suffix can also be added.

There are currently 3 different techniques to create the unique IDs:

UNIVERSALLY UNIQUE IDENTIFIER – random 32 characters, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
RANDOM WITHIN RANGE – unique random numbers within a defined range
INTERVAL – based on a user defined interval

Be sure to view the Tool Help within the tool dialog box for detailed instructions. Also, check the Geoprocessing Results for any error messages.

Here’s a screenshot of the parameters:
Create Unique IDs parameters

I hope someone finds this tool useful. Please leave a comment if you have any questions or problems, and be sure to check out the other tools I’ve created!

11 thoughts on “ArcGIS Toolbox – Create Unique ID with ArcPy

  1. bill@TLH
    May 16, 2014 at 9:58 am

    Howdy Ian.
    Would this tool work on a selected set of records in a feature class?
    Thank you, sir.

  2. Marcus
    August 1, 2014 at 4:04 pm

    would you happen to something like this for Arc 10.0?

    1. Ian
      August 2, 2014 at 4:28 pm

      No, I don’t, sorry. I believe the only reason this tool doesn’t work with 10.0 is because of the use of da cursors. You could pretty easily convert the code to use the standard cursors.

  3. Glenn
    June 14, 2015 at 4:14 am

    This tool is very useful tool specially if you are working on an attribute table specially during join and relate process.Thanks a lot ian.

    1. Ian
      June 17, 2015 at 11:43 am

      Thanks, Glenn!

  4. Erik
    January 26, 2016 at 8:33 am

    This was very helpful. Thank you!

    One question- is it possible to define the min & max values for a range vs. just the max? I need to generate 5 digit unique ID’s. It would be great to set the range 10000 – 99999

    1. Ian
      February 3, 2016 at 11:58 am

      Thanks for the comment, Erik! Currently, there’s no way to do this, but it that functionality could definitely be added.

  5. Joe Hu
    April 28, 2016 at 10:37 am

    Does not work with arcmap 10.3.1, I have tried many times, it has error sign at the top line when I add tool box.
    Would you fix it?

    ERROR
    updateParameters Syntax Error: Runtime error Traceback (most recent call last): File “C:\Users\HU_J\Downloads\CreateUniqueIDs\CreateUniqueIDs\CreateUniqueIDs.tbx#CreateUniqueIDs_CreateUniqueIDs.UpdateParameters.py”, line 1, in File “c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\__init__.py”, line 24, in from arcpy.toolbox import * File “c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\toolbox.py”, line 359, in from .management import Graph, GraphTemplate File “c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py”, line 26, in import _management File “c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\_management.py”, line 14, in import _graph File “c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\_graph.py”, line 27, in import numpy ImportError: No module named numpy

    1. Ian
      April 28, 2016 at 8:04 pm

      Hi Joe, the `ImportError: No module named numpy` error is usually a problem with your arcpy install.

      Please see my answer here: http://gis.stackexchange.com/a/189384/12159

  6. Deo
    September 8, 2016 at 3:55 am

    Hi Ian,

    It’s really perfect tool and am just wonder if there’s way when line feature is split the old ID is preserved as parent ID and the two new features after splitting take up the IDs in relation to parent ID.
    For example if having line feature with ID TNG00235 I would like when the line is split the child IDs to be like TNG00235_1 and TNG00235_2.

    Thanks.
    Deo

    1. Ian
      September 8, 2016 at 9:18 pm

      Hi Deo, glad it’s working for you. I believe you would need a custom split tool developed that would basically recreate the lines and assign the correct IDs. This toolbox will not do that for you. Hope this helps, and thanks for the comment.

Leave a Reply

Your email address will not be published.