Batch Update Aliases

5102
12
06-04-2018 09:41 AM

Batch Update Aliases

ArcGIS custom toolbox which uses a python script, for updating a mass amount of field aliases at once, using a list of field names and corresponding aliases input by user.

Let’s say you have an ArcGIS feature class or table with a bunch of cryptic, abbreviated field names, and you want to add aliases to make them easier to understand. Let’s say you also have a list of field names and corresponding aliases that you have prepared in Excel or whatever. All you need to do is save that list as a CSV file with the field names in the first column and aliases in the second column. Then run this tool. The only inputs required are the feature class and the CSV file.

The script uses the arcpy and csv packages. It first reads the CSV file and parses it into a python list where each item in the list is a list containing a field name and alias value. Then it iterates through that list, running an arcpy command that attempts to update the alias for each field name in the list. As the tool is running, it will display a message for each field that gets an updated alias. If a field name from your list does not exist in the feature class, the tool will display a message telling you that and move on to the next one. It should take just a few seconds per field to run.

I ran this tool successfully with ArcGIS Desktop 10.5. I believe it could also be tweaked to work on a shapefile instead of a feature class. It’s really a pretty simple script, and I’m probably not the first person to come up with something like this, but I couldn’t find a solution searching elsewhere. Please let me know or suggest changes if it doesn’t work for you.

Attachments
Comments

This worked GREAT! Thanks so Much!

Can you please help me to find a script for this toolbox. I tried to download but could not find any script inside the toolbox. I am using 10.3.1. Thanks. 

Ravi, In order to see the script inside the toolbox, you have to add it as a custom toolbox first. To add a custom toolbox, in ArcMap or ArcCatalog, open ArcToolbox and right click in the white space and go to Add Toolbox:

source: arcgis desktop - How can I add a custom toolbox to ArcMap, and see its script? - Geographic Informat... 

Please let me know if you have any issues.

Hi Dustin, thanks for your response. I tried the same and could add the Toolbox but it does not have any script inside it. It would be great if you could share the script if you have it. Thanks. 

This is so awesome.. Great work. I have been looking for a solution like this for a while now. Thanks!

Glad you found it helpful!

This saved me so much time I'd have wasted on tedious BS.  Thank you so much

Thanks Matthew, this looks like a great tool!

I'm getting an error when running:

Running script Batch Update Aliases...
Failed script Batch Update Aliases...
Traceback (most recent call last):
File "C:\Users\Jordan\Downloads\Update_Aliases.tbx\Update_Aliases.tbx#BatchUpdateAliases.py", line 25, in <module>
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Failed to execute (BatchUpdateAliases).

Any thoughts on what is causing this?

Much appreciated,

Jordan

Thanks for your comment, and sorry I haven't replied sooner.  I'm not sure what the issue is - I would have to investigate.  Unfortunately it's not a priority for me in my current job, but I will try to look into this when I get a chance...

Thanks for sharing this, Matthew. I was just going to write my own version and you saved me a bunch of time. Worked perfectly in 10.7. Cheers!

@MatthewLeonard I'm also not seeing the script after adding the toolbox. Can you provide the script used to bulk update the field aliases?

@DaltonBloom you may need to unzip (extract) the files once downloaded, and rename the extracted directory to be something other than 'Update_Aliases.tbx', as it also didn't appear for me, but when I renamed the directory that the Toolbox was in it appeared / would add to ArcGIS Pro.

@Jordan I also experienced the 'Error: iterator should return strings, not bytes', on inspecting the toolbox script at the identified line it appears the csv is opened in binary mode. If you amend the text from;
with open(in_csv, 'rb') as csvfile:
to
with open(in_csv) as csvfile:
then it may work - as it appeared to start working for me.

I am updating alias' to a PostgreSQL GeoDatabase to a table that has +1m rows and the tool is a bit slow at setting the alias', I could possibly have renamed them manually quicker - however using the tool will obviously free me up to do other things. To set the alias' for 92 attributes it took (my computer / Windows Surface Book 2) 57 minutes. I tried again with an empty table and it wasn't any quicker.

Thanks to @MatthewLeonard for this solution, having explored FME (long winded) and ESRI user interface options (non-existent) this script is the best way I've come across to batch update many attribute alias' in one go, which is incredibly helpful

Version history
Last update:
‎06-04-2018 09:41 AM
Updated by:
Contributors