I am new to working in ArcGIS Desktop.

I have feature point data with 3 fields in table attribute (objectID, shape and sequence).

I want to add another field lets say called "name_sequence)..

in the name_sequence field i want to add text which have format "x+yyy", ("x", "+", "yyy")

in loop every 100, start with 0+000..

so it become like this

0+000, 0+100, 0+200, .... 0+900

the point after +900 it will add "x+1" so in data no 11 it'll show 1+000 after that it will have same sequence as i mention above.. furthermore, after i searching the code i found we can use range function and concatenate function to do that.. so i come with the code like this in field calculator.. using VB

 for i = 1 to 10
     a = i
     b = i*100
     srt_join = concat(srt(a),"+", srt(b))
 end for 

i know it might be totally wrong code or it is not complete yet.

so i want to know what should i add for this code?

or do you have another way to do this?

and i want know new understanding about coding in arcgis

for your understanding i attach the result of my data which i working in excel.

enter image description here


It's not clear if you're trying to do this in a script or from the field calculator; for my example I have added a field called Name_Seq (10 character limit in a shapefile):

Table after calculation

Assuming this is what you want a simple python code block will do the trick in field calculator:

bCnt = 0 # initialize this variable to 0, we will use this with global

def CalcThisField():
    global bCnt                # tell python that this isn't a new variable
    bStr = str(bCnt).zfill(2)  # zfill (fill with leading 0's for numbers less than 10
    # break up and format the string
    fVal = '{}+{}00'.format(bStr[0], bStr[1])
    bCnt += 1                  # Increment the counter
    return fVal                # return the result

Used in the field calculator dialog like this:

enter image description here

Note the use of brackets is important as you want the value returned by the function and not the function itself to be in your string field.

Please note that this will have a big problem when you hit 100 features.. it is only using the first and second character of the string so will go back to 1+000 for 10 rows then 1+100 for the next 10 rows etc. If you want to increment the first number so that at feature 100 the value changes to 10+000 this can be easily done in python using negative string indexing:

fVal = '{}+{}'.format(bStr[:-1],bStr[-1:]) # all but the last character + last character + 00

You can also use the UpdateCursor in the Python window of ArcMap:

import arcpy
fc = r"C:\data.gdb\feature" #Change
hundreds = (i for i in range(0,1000000,100)) #Generator which yields 0,100,200,...,1000,1100 etc.

with arcpy.da.UpdateCursor(fc,"Name_Seq") as cursor:
    for row in cursor:
        seq = str(next(hundreds)).zfill(4) # 0->0000, 100->0100, 1000->1000
        row = "{0}+{1}".format(seq[0],seq[1:])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.