Python Code to create FacilityID based on ObjectID

651
2
Jump to solution
06-16-2022 12:51 PM
Labels (3)
MattCotterill
Occasional Contributor

I'm a beginning Python user.

Using ArcGIS Pro 2.9.2, I'd like to use python code in the field calculator to generate unique IDs based on the Object ID field. The unique ID should be 3 letters followed by a dash, followed by five digits. It should be a string. For example:

Object ID 1 should generate 'Bcn-00001'
Object ID 10 should generate 'Bcn-00010'

I was thinking something like:

FacID = .str('Bcn-000+!OBJECTID!')

I don't know how to make the number of zeros in front of the Object ID vary based on the number of digits in the Object ID

Thanks!

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
"Bcn-{0:0>5}".format(1)
'Bcn-00001'

"Bcn-{0:0>5}".format(100)
'Bcn-00100'

plus other variants


... sort of retired...

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor
"Bcn-{0:0>5}".format(1)
'Bcn-00001'

"Bcn-{0:0>5}".format(100)
'Bcn-00100'

plus other variants


... sort of retired...
MattCotterill
Occasional Contributor

Thanks!

0 Kudos