0

Using the Field Calculator, I want to create prefixed, padded IDs from an existing number field. By "padded", I mean I want the IDs to have a specific number of characters, regardless of how many digits the numbers have.

For example, I want to use the values in OBJECTID to create IDs like:

  • OBJECTID 8 >>> INSP000008
  • OBJECTID 9 >>> INSP000009
  • OBJECTID 10 >> INSP000010
  • OBJECTID 11 >> INSP000011

Note: All the resulting IDs have the same number of characters (10).

How can I do this?

1 Answer 1

0

I modified the logic from my Sequential IDs script. I changed it to use the values in an existing number field, rather than generating sequential IDs.

It seems to do the trick:

prefix="INSP"
numlength=6

def IDfromNumberField(num):
    return prefix+'%s' %str(num).zfill(numlength)

__esri_field_calculator_splitter__
IDfromNumberField( !YourExistingNumberFieldHere! )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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