Generate point names based on existing attribute columns?

755
1
03-12-2017 06:32 PM
JessicaBlackman
New Contributor

Hi guys, 

I am trying to work out a calculation (either python or VBscript) in ArcGIS that will enable me to calculate mass site names that include both text and sequential numbers. 

I need a field calculation that will add the same text at the start of each attribute (e.g. "JCB-"), and then a number following it which corresponds to the site's numerical unique ID. So for example:

I have a site, with an ID of 1994. It was found at a location called JCB, so its site name needs to be JCB-1994. Then, the following site ID may be 458, so it would be JCB-458. As they may not be consecutive numbers, I need the field calculator to take the numerical information from the existing attribute ID and not simply run the next consecutive number. 

Can anybody suggest a script I can use? I have used something similar in the past but have recently moved office and lost the reference sheet I was using

I thank you in advance!  

Jess

0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus
txt = "JCB"
site = 194
"{}-{}".format(txt, site)
'JCB-194'‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Python parser, field calculator, assume 'txt is a field's name (ie it will look like this in python when you select it ... !txt!) Now assume your other field (or whatever) is ID (ergo !ID! in the field calculator...

So the above does the fancy conversion of a number to a string and you just whip a - in it.  In python 3.6, the format thing is replaced with a much simpler version, but you are some time away from being able to use it in Arc

Coming up ... to a python hopefully soon

>>> f"{txt}-{site}"   # python 3.6 and 3.7
'JCB-194'
>>>