Hi Friends,
kindly attached .gdb, example excel sheet, and image for your reference. I want to create a unique id 001 for each batch have 30 point feature, next 30 point feature I want to create 002....etc like that
I want to create at a time any arcpy code available please help me.
I want to create a unique at a time like 001,002,003....etc each batch has 30 point features see the example below.
Thanks
Santhosh
Solved! Go to Solution.
I just used a Notebook and tried this code and it worked. A little different from the original code that runs in Spyder:
intCurrentBatch = 1
intStartNumber = 1
intBatchSize = 10
intBSAfterFirstTimeThrough = intBatchSize - 1
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if intStartNumber <= intBatchSize:
row[0] = str(intCurrentBatch).zfill(4)
cursor.updateRow(row)
intStartNumber = intStartNumber + 1
else:
intStartNumber = 1
intCurrentBatch = intCurrentBatch + 1
row[0] = str(intCurrentBatch).zfill(4)
cursor.updateRow(row)
intBatchSize = intBSAfterFirstTimeThrough
Image of Notebook. Keep in mind that indentation level is important.
Results
There might be more elegant ways of doing it but this worked for me. I wrote this in Spyder:
result in my test data:
Hi KimGarbade,
Can you share with me the above code? Exactly I am looking at the above result.
Thanks
Santhosh
Sorry, I'm not at the computer I wrote that code on (that was my home PC). So I don't have a text version of the code here (at work), but the code I used was in the first image above. There are no lines of code either above or below the lines shown (no lines below line 27).
I wrote the code in Spyder, which is a third party Python editor, but it should work in any python environment that supports arcpy.
Hi KimGarbade,
when I was using the above code it's showing the error message. can you see the below image for your reference
Thanks
Santhosh
I just used a Notebook and tried this code and it worked. A little different from the original code that runs in Spyder:
intCurrentBatch = 1
intStartNumber = 1
intBatchSize = 10
intBSAfterFirstTimeThrough = intBatchSize - 1
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if intStartNumber <= intBatchSize:
row[0] = str(intCurrentBatch).zfill(4)
cursor.updateRow(row)
intStartNumber = intStartNumber + 1
else:
intStartNumber = 1
intCurrentBatch = intCurrentBatch + 1
row[0] = str(intCurrentBatch).zfill(4)
cursor.updateRow(row)
intBatchSize = intBSAfterFirstTimeThrough
Image of Notebook. Keep in mind that indentation level is important.
Results
Hi KimGarbade,
Finally, I got the Result of my data Thank you so much for your help.
Thanks
Santhosh
Result in my data below