<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create sequential unique ID field based on an advanced sorting in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722508#M55942</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, It's been the weekend here, hence why I haven't responded. I will check the code as soon as I can. Also this is the only post on this subject I have created.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 03 May 2015 23:55:22 GMT</pubDate>
    <dc:creator>AndrewNeedham</dc:creator>
    <dc:date>2015-05-03T23:55:22Z</dc:date>
    <item>
      <title>Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722496#M55930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Arial',sans-serif; color: black;"&gt;Hi All&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Arial',sans-serif; color: black;"&gt;Is it possible to create sequential unique ID field based on an advanced sorting of the attributes using Python? And without installing &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;ET GeoWizards&lt;/SPAN&gt;? (ArcGIS 10.2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: #000000; font-family: Arial, sans-serif;"&gt;This doesn't work&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Arial',sans-serif; color: black;"&gt;&lt;A href="http://support.esri.com/en/knowledgebase/techarticles/detail/38517" title="http://support.esri.com/en/knowledgebase/techarticles/detail/38517"&gt;38517 - Create sequential numbers in a field using Python in the Field Calculator&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;ET GeoWizards&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Arial',sans-serif; color: black;"&gt;&lt;A href="https://community.esri.com/thread/96828"&gt;SOLUTION for adding new sequential ID numbers based on sorted data&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Arial',sans-serif; color: black;"&gt;Cheers&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 02:33:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722496#M55930</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-01T02:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722497#M55931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And you don't have the advanced license either do you?&amp;nbsp; &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Sort/001700000057000000/"&gt; Sort tool help &lt;/A&gt;&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 02:59:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722497#M55931</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T02:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722498#M55932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I have &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;advanced license&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 03:51:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722498#M55932</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-01T03:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722499#M55933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​The link I provided has a discussion.&amp;nbsp; You will at least be able to determine whether it meets your needs then.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 03:53:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722499#M55933</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T03:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722500#M55934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's one workaround, I would also get the same result by adding a new field (for the Unique ID's) , Advanced sorting the data, then copying attributes to excel, adding &lt;SPAN style="color: #000000; font-family: Arial, sans-serif;"&gt;sequential numbers then copying back to Arc while editing. It would be nice to have the ability of field calculator with selections etc, using python.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 04:08:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722500#M55934</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-01T04:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722501#M55935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Edit&lt;/P&gt;&lt;P&gt;Forgot autoincrement uses the feature ID.&amp;nbsp; I will try to find a simpler workaround and post it (numpy offers possibilities)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 04:12:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722501#M55935</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T04:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722502#M55936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The autoincrement doesn't work on sorted fields, it works off the created order eg FID/ObjectID&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 04:22:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722502#M55936</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-01T04:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722503#M55937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​yes I caught that and edit mine a while ago.&lt;/P&gt;&lt;P&gt;don't have arcmap on the iThingy, I was thinking of a workaround when sorting on geometry is done,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 04:34:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722503#M55937</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T04:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722504#M55938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thought I dealt with this before, I wrote it down&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/48013"&gt;Sorting and ranking... arcpy and numpy play nice...&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 17:43:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722504#M55938</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T17:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722505#M55939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you try something like this?&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;If applicable, &lt;A href="http://resources.arcgis.com/en/help/main/10.1/0017/001700000047000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Add Field&lt;/A&gt; to store sequential id&lt;/LI&gt;&lt;LI&gt;Since you're on 10.2, you can create an &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/searchcursor-class.htm#C_GUID-3CB1DFF4-983D-445F-9CB2-0FF1CD4B4880" rel="nofollow noopener noreferrer" target="_blank"&gt;update cursor&lt;/A&gt; with a sql clause using &lt;SPAN style="font-family: 'courier new', courier;"&gt;ORDER BY&lt;/SPAN&gt; (see second to last code sample). The link is for 10.3 but I've tested this in 10.2.2 on SDE and file geodatabase just fine.&lt;/LI&gt;&lt;LI&gt;Set up the iteration on the &lt;A _jive_internal="true" href="https://community.esri.com/message/494701#494701" target="_blank"&gt;cursor using enumeration&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Iterate through the cursor and update the sequential id field with the enumeration number&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't tested this, but here's an example:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp;&amp;nbsp; temp_gdb = r"C:\Temp\MyGDB.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = os.path.join(temp_gdb, "MyFC")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, "SeqID", "SHORT")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 2
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ["OID@", "MySortField", "SeqID"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, fields, sql_clause=(None, 'ORDER BY MySortField')) as u_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for seqid, row in enumerate(u_cursor, start=1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = seqid
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;u_cursor&lt;/SPAN&gt;.updateRow(row)


if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:54:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722505#M55939</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T06:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722506#M55940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​Me thinks he is no longer interested having found a solution on one of several sites he posted the question on... &lt;A href="http://stackoverflow.com/questions/29961738/creating-multiple-fields-with-ranks-using-arcpy" title="http://stackoverflow.com/questions/29961738/creating-multiple-fields-with-ranks-using-arcpy"&gt;python - Creating multiple fields with ranks using arcpy - Stack Overflow&lt;/A&gt;&amp;nbsp;&amp;nbsp; which references an Arcpy article&amp;nbsp; &lt;A href="https://arcpy.wordpress.com/2013/08/02/ranking-field-values/" title="https://arcpy.wordpress.com/2013/08/02/ranking-field-values/"&gt;Ranking field values | ArcPy Café&lt;/A&gt;&amp;nbsp; with the cavaet that it doesn't work in these situations...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" &lt;EM style="font-family: Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px; color: #323232;"&gt;Note: dBase (and shapefiles) does not support ORDER BY as used above by &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000014000000" style="font-family: inherit; font-size: inherit; font-style: inherit; color: #0d3d9b;"&gt;arcpy.da.UpdateCursor’s&lt;/A&gt; sql_clause argument.&lt;/EM&gt; "&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 23:43:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722506#M55940</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-01T23:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722507#M55941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like the solution posted there is very similar to mine. Thanks for the follow-up Dan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 23:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722507#M55941</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-05-01T23:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722508#M55942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, It's been the weekend here, hence why I haven't responded. I will check the code as soon as I can. Also this is the only post on this subject I have created.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 May 2015 23:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722508#M55942</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-03T23:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722509#M55943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Blake,&lt;/P&gt;&lt;P&gt;Thanks for the code, I'll see how this works as soon as I can.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 May 2015 23:56:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722509#M55943</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-03T23:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722510#M55944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Blake, I tried the code but It didn't populate the new field.&lt;/P&gt;&lt;P&gt;I'll just stick to the Excel way as is will be quicker.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2015 04:20:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722510#M55944</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-04T04:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722511#M55945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you like, post the code you used and we can help you debug it.&lt;/P&gt;&lt;P&gt;I just tested my logic and it worked in a file geodatabase. Here is updated code that is a little more flexible.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp;&amp;nbsp; temp_gdb = r"N:\TechTemp\BlakeT\Work\TEMP.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = os.path.join(temp_gdb, "TEMP_Line")
&amp;nbsp;&amp;nbsp;&amp;nbsp; sortFieldName = "Note1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; seqFieldName = "SeqID"

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; existingFields = [field.name for field in arcpy.ListFields(fc)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if seqFieldName not in existingFields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, seqFieldName, "SHORT")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 2
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursorFields = [sortFieldName, seqFieldName]
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql_postfix = 'ORDER BY {}'.format(sortFieldName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, cursorFields, sql_clause=(None, sql_postfix)) as u_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for seqid, row in enumerate(u_cursor, start=1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = seqid
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u_cursor.updateRow(row)


if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:54:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722511#M55945</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T06:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722512#M55946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Blake, &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 04:44:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722512#M55946</guid>
      <dc:creator>AndrewNeedham</dc:creator>
      <dc:date>2015-05-05T04:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create sequential unique ID field based on an advanced sorting</title>
      <link>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722513#M55947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome, I tweaked it a bit more to allow for setup as a tool with parameters, NICE WORK!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jan 2018 00:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-sequential-unique-id-field-based-on-an/m-p/722513#M55947</guid>
      <dc:creator>ChadFoster1</dc:creator>
      <dc:date>2018-01-30T00:22:25Z</dc:date>
    </item>
  </channel>
</rss>

