import arcpy input = "H:/GIS_Data/TEMP_GDB.gdb/feattoline" # your feature class fields = "OID A; Type A" # sort by OID, ascending, then Type, ascending rows = arcpy.UpdateCursor(input,"","","",fields) count = 0 for row in rows: if count == 0: curType = row.Type count = count + 1 if row.Type != curType: curType = row.Type count = 1 row.Type_Num = count rows.updateRow(row) del row del rows
I have a set of records:
OID,Type
1,A
2,B
3,A
4,B
5,C
6,C
7,B
8,B
9,A
I'd like to use a python script to add a sequential unique ID by type...
OID,Type,Type_Num
1,A,1
2,B,1
3,A,2
4,B,2
5,C,1
6,C,2
7,B,3
8,B,4
9,A,3
So far i've attempted looping through a list of types but with only partial success and i'm convinced i'm way off base as evidenced by code below...
rec=0
L=["A","B","C"]
def doit (Type) :
for name in L :
while Type == name :
global rec
rec = rec + 1
return rec
rec=0
__esri_field_calculator_splitter__
doit (!Type!)
My ultimate goal is to reference my records in the fashion A1, A2, A3, B1, B2, B3 etc. Any thoughts or suggestions would be much appreciated. Obviously i'm VERY new to Python.
import arcpy Acount = 0 Bcount = 0 Ccount = 0 rows = arcpy.UpdateCursor("mydata", "", "", "OID; Type; Type_Num", "OID A") for row in rows: if row.Type == 'A': Acount = Acount+1 row.Type_Num = Acount elif row.Type == 'B': Bcount = Bcount+1 row.Type_Num = Bcount elif row.Type == 'C': Ccount = Ccount+1 row.Type_Num = Ccount rows.updateRow(row) del row del rows