ArcMap modify gdb and update layers in TOC

517
7
06-12-2017 10:07 AM
Highlighted
Occasional Contributor

I created multiple maps using the data stored in one geodatabase (all layers pointing this geodatabase).  I modified geodatabase layers' alias, but layers in TOC weren't updated.  I prefer not to recreate maps by adding layers again and setting the definition query and symbology and so on.

Q.  Is there a way to update layers' alias in TOC in ArcMap without re-adding the layers to the map?

Thank you in advance.

Tags (1)
7 Replies
Highlighted
MVP Notable Contributor

Makiko,

This is a great question. It might be best to have this question in the https://community.esri.com/community/gis/managing-data?sr=search&searchId=df3ab0eb-520a-4459-a846-84...‌ space. The GeoNet Help is for help with the GeoNet.

Highlighted
MVP Esteemed Contributor

moved to Managing Data‌ 

GeoNet Community Structure for your info

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Make a backup of the MXD, just in case, but I think the following will work for you (from the interactive Python window in ArcMap):

>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> lyrs = arcpy.mapping.ListLayers(mxd)
>>> for lyr in lyrs:
...     try:
...         desc = arcpy.Describe(lyr.dataSource)
...         lyr.name = desc.aliasName
...     except NameError:
...         pass
...        
>>> arcpy.RefreshActiveView()
>>>
Highlighted
Occasional Contributor

Hi Adrian and Dan,

I was having difficulty to find the correct place to ask a question.  Thank you for moving my question in right place.  

Hi Joshua,  

Thank you so much for your reply and Python code.  I am wondering that if it can be done without Python.  I thought layer update can be done easily such as clearing database cache and refreshing the TOC.  I couldn't find a way to do it in ArcMap.

I will keep open my question since I am curious if there is a way to do it in ArcMap.  Meanwhile, Python is the best option so I will use it for my work.

Thank you!

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

I updated the code to trap and dismiss errors for layers that don't have a dataSource property, like group layers.

Unfortunately, I am pretty sure the way to do it in ArcMap is the same process the Python snippet uses, i.e., visit each layer and update the name.  I may be wrong, maybe someone will share a slicker way to do it.

If clearing the database cache and refreshing the TOC worked, it would cause all sort of problems for users.  What if a DBA changed an alias for a feature class and a user didn't want the layer to be automatically renamed in their TOC?  I think most users would not want their TOC changing if a database cache was cleared.

Highlighted
Occasional Contributor

Thank you, Joshua.

If clearing the database cache and refreshing the TOC worked, it would cause all sort of problems for users.

You are correct. Some users want to create their own alias in their maps, so changing a layer instance alias in ArcMap works for them well. As you mentioned, it is a huge problem if the layer alias is renamed automatically. On the other hand, for some users (like my organization) the database is the primary source, meaning all instances of layers that consume data from certain database in ArcMap need to be updated when the database is modified. This is the reason why I am interested in whether there is a way to manually (or otherwise) change an ArcMap setting, but it seems it is a good idea to create a Python scripting tool for this so I can share the tool with my colleague.

Again, thank you so much for your response!!  

Highlighted
MVP Notable Contributor

Makiko,

Like Joshua said, it looks like Python uses the same process you would have to take but makes it more automatic. I would suggest using that method with the Python snippet provided. It seems like it would be even less steps to use this Python snippet than to go through with clearing a database cache and refreshing the TOC (and of course the issue Joshua brought up with what could happen with clearing the cache, etc.).

Reply
0 Kudos