<?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 script for entering alphabetical text field values in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125471#M48981</link>
    <description>&lt;P&gt;Hi ESRI Community -&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 2.9.0.&lt;/P&gt;&lt;P&gt;I was looking to automatically generate text field values (Sub-compartment field) that can be assigned to a pre-exisiting numeric field (Compartments).&lt;/P&gt;&lt;P&gt;eg - I have polygons assigned to compartment numbers 1 through to 50, with multiple polygons assigned to each compartment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What Id like to do in the sub-compartment field is to automatically generate a unique alphabetical text label that is assigned to each compartment polygon - ie 1a,1b,1c, 2a, 2b...2z,...etc.&amp;nbsp; Where there are more than 26 polygons for a given compartment, the labels can go to 1a1,1b1 etc, to save manually entering values for each polygon.&lt;/P&gt;&lt;P&gt;Any suggestions please?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;rhys&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2021 17:02:29 GMT</pubDate>
    <dc:creator>RhysLlewellyn</dc:creator>
    <dc:date>2021-12-13T17:02:29Z</dc:date>
    <item>
      <title>script for entering alphabetical text field values</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125471#M48981</link>
      <description>&lt;P&gt;Hi ESRI Community -&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 2.9.0.&lt;/P&gt;&lt;P&gt;I was looking to automatically generate text field values (Sub-compartment field) that can be assigned to a pre-exisiting numeric field (Compartments).&lt;/P&gt;&lt;P&gt;eg - I have polygons assigned to compartment numbers 1 through to 50, with multiple polygons assigned to each compartment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What Id like to do in the sub-compartment field is to automatically generate a unique alphabetical text label that is assigned to each compartment polygon - ie 1a,1b,1c, 2a, 2b...2z,...etc.&amp;nbsp; Where there are more than 26 polygons for a given compartment, the labels can go to 1a1,1b1 etc, to save manually entering values for each polygon.&lt;/P&gt;&lt;P&gt;Any suggestions please?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;rhys&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 17:02:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125471#M48981</guid>
      <dc:creator>RhysLlewellyn</dc:creator>
      <dc:date>2021-12-13T17:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: script for entering alphabetical text field values</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125491#M48984</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/76816"&gt;@RhysLlewellyn&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;If you are looking to accomplish assigning unique values to component within the range of the main component, then a more suggested manner in which to accomplish this would be to use a counter. Simply put, a counter will automatically assign a unique incrementing value to each sub-compartment of the main compartment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So one of several ways to assign the unique sub-compartment values is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

updates = {}

feature_class = #file location for the feature class
fields = # list of fields to which to update the feature class based on the compartment field and the sub-compartment field

with arcpy.da.UpdateCursor(feature_class, fields) as Main_Cursor: # update feature class
    for row in Main_Cursor: # loop through the feature
        if row[0] not in updates and row[1] is not None:
            updates[row[0]] = row[1]
        elif row[0] in updates and row[1] is None: # check if row[0] in updates dict
            update_value = updates[row[0]] + 1 # acquire value from updates dict and increase by 1
            updates[row[0]] = update_value # update key with updated value

            row[0] = row[0] # assign row[0] same value as self
            row[1] = updates[row[0]] # assign row[1] as updates value
            Main_Cursor.updateRow(row) # update row

        else:
            updates[row[0]] = 0 # assign row[0] as key and 0 as value
            row[0] = row[0] # assign row[0] same value as self
            row[1] = updates[row[0]] # assign row[1] value of updates[row[0]]
            Main_Cursor.updateRow(row) # update row
del Main_Cursor # del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you would like to do would be a more complicated approach than simply using a counter.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 12:53:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125491#M48984</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-12-14T12:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: script for entering alphabetical text field values</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125565#M48987</link>
      <description>&lt;P&gt;Conceptually with python:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Select Compartment Polygon (probably from a list)&lt;/LI&gt;&lt;LI&gt;Spatially select those subcompartments within the compartment&lt;/LI&gt;&lt;LI&gt;Get a count of the number of subcompartments&lt;/LI&gt;&lt;LI&gt;If Count &amp;lt;= 26&lt;UL&gt;&lt;LI&gt;Call an update cursor routine that updates the the subcompartmentField with CompartmentID and a letter&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;else if count &amp;gt; 25 and &amp;lt; 51&lt;UL&gt;&lt;LI&gt;call a different cursor&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;See code below for what I came up with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import string

alphaList = list(string.ascii_lowercase)
   value = 0
    compartmentID = 25 # from a list of your compartments feature class
                       #you'll need to nest all of this in another loop
    NumberofSubCompartments = 15 + 1 # get 15 from the count of sub- 
                                     #compartments
    for count in range(1,NumberofSubCompartments):
        if value &amp;lt;= 25:
            a = alphaList[value]
            value +=1
            print(f'{compartmentID}{a}')
        elif value &amp;gt; 25 and value &amp;lt; 51:
            for a in alphaList:
                print(f'{compartmentID}{a}{value}')
                value += 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No warranties or guarantees.&amp;nbsp; This is conceptual at best.&amp;nbsp; Plug in different values&amp;nbsp; in line 6 that would be the count of sub-compartments.&amp;nbsp; Those lines that use the print(fString), create the value to plug into the update cursor.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;subCompartmentId = f'{compartmentID}{a}'
#add your update cusor here and

subcompartmentId = f'{compartmentID}{a}{value}'
#add your update cursor here...&lt;/LI-CODE&gt;&lt;P&gt;I&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 20:32:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125565#M48987</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-13T20:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: script for entering alphabetical text field values</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125756#M49003</link>
      <description>&lt;P&gt;Thanks Joe - I'll have a look.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 10:13:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125756#M49003</guid>
      <dc:creator>RhysLlewellyn</dc:creator>
      <dc:date>2021-12-14T10:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: script for entering alphabetical text field values</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125759#M49004</link>
      <description>&lt;P&gt;Thanks for the tip RGPIS, will let you know how I get on.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 10:14:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-for-entering-alphabetical-text-field-values/m-p/1125759#M49004</guid>
      <dc:creator>RhysLlewellyn</dc:creator>
      <dc:date>2021-12-14T10:14:27Z</dc:date>
    </item>
  </channel>
</rss>

