Select to view content in your preferred language

Sort Field and then Calculate Sequential Values

6988
15
06-22-2018 10:40 AM
deleted-user-jxpbpbjlZInj
Deactivated User

I have ZERO experience with ArcPy, Arcade expressions... yadda yadda. I basically limp along until something magically works and I'm a huge fan of Copy/Paste. THAT SAID, I'm dipping my toe into something that I thought would be easy...

I have a bunch of campgrounds, and these are in some parks. I want to give them sequential values based on sorting the PARK_NAME field alphabetically. Using Python 3 in Field Calculator, "Sequential Number" will only assign sequential values based on the Object ID field - it doesn't care how I've sorted it.

How do I tell it to use my sorted field instead of the Object ID? Help! 

15 Replies
DanPatterson_Retired
MVP Emeritus

/blogs/dan_patterson/2018/02/12/table-tools-a-set-of-tools-for-working-with-tabular-data is a description to the Code sharing site for my set of table tools.

Calculations for text fields may be what you are looking for... but a better example of your desired output might help

deleted-user-jxpbpbjlZInj
Deactivated User

Alrighty in this table I've run the Sequential python 3 straight from the calculate field options and this is sorted ascending OID. You can see that the sequential values were assigned by the OID. I don't want this:

In this next screen shot, I've ordered park name ascending by alphabet. I would prefer that the CampgroundID would then be "001, 002, 003", but it's not...  

Does this help explain what I'm looking for? Just downloaded Table Tools!!  

0 Kudos
DanPatterson_Retired
MVP Emeritus

let me know if it works or you have any issues... I never got many applicable test cases … it was more an exercise in coding

0 Kudos
deleted-user-jxpbpbjlZInj
Deactivated User

Hey Dan, 

So I'm circling back around to this item. I've got table tools and I ran Text Fields and keep getting this error:

Traceback (most recent call last):
File "c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Scripts\sequential_funcs_txt.py", line 199, in <module>
in_tbl, in_arr, in_fld, out_fld, del_fld, func, xtend = _tool()
File "c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Scripts\sequential_funcs_txt.py", line 185, in _tool
in_arr = tbl_2_np_array(in_tbl, flds)
NameError: name 'tbl_2_np_array' is not defined
Failed to execute (TxtFieldCalculations).

0 Kudos
DanPatterson_Retired
MVP Emeritus

like sequential number text fields?


0 Kudos
deleted-user-jxpbpbjlZInj
Deactivated User

Yes! Exactly. I keep trying to run this - even trying different tables - and it is giving me the above error. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

I will check the version online... had some issues with things not being updated.  I have attached a zip... try it

unzip into a folder and run from there.

don't separate anything and make sure the destination folder has no spaces (i don't tolerate them)

if this doesn't work, zip and email a copy of the table in a gdb (remove fluff and anonymize if needed) and I will have a look at it.

deleted-user-jxpbpbjlZInj
Deactivated User

Ok, interesting! So I took the same layer and threw it into the toolbox from your zip file. This is a layer in an Enterprise Geodatabase that I have full editing privileges to. It said that it failed because it didn't want to work outside of an edit session (I'm working in ArcGIS Pro 2.2.4)... so I exported out the feature layer to the project geodatabase and ran the tool and it worked fine. Hmmm. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Work local.  Enterprise is for Star Trek.  You can get a full refund if you aren't satisfied

0 Kudos