3

I often work with MXDs that have a large number of group layers, and would like to find a specific layer by name (either TOC given name or an original file name) in the Table of Contents.

I tried Ctrl+F and search options, but that's not what I'm after.

Is there a shortcut or an option for this in ArcMap?

5
  • 1
    To my knowledge there is no way to search a TOC for the currently opened MXD. You would need to write custom code to achieve this.
    – Hornbydd
    Commented Jul 13, 2015 at 13:55
  • In the TOC options you can change the sort order from the order they are drawn to Layer Name which might help
    – MAJ742
    Commented Jul 13, 2015 at 14:07
  • I was also going to add an answer about using the indexing function in the search toolbar, but this would only search a folder location and enable a layer to be added but not search the TOC itself. resources.arcgis.com/en/help/main/10.1/index.html#//…
    – MAJ742
    Commented Jul 13, 2015 at 14:28
  • 1
    Thanks for the suggestions. It seems as this should be so simple!
    – Magda
    Commented Jul 13, 2015 at 14:39
  • 1
    it's a builtin feature in arcgis pro . For arcmap, you should write arcobject code to do so. Commented Aug 25, 2015 at 8:26

2 Answers 2

1

I once used Arc Crawler (or MXD Crawler) that could maybe answer your question but I couldn't make it work again on my Arcgis 10.X version. Seems to work for ArcGIS 9.3

enter image description here

1

The other option is to populate the ArcMap Document (mxd) tags with the layer names under File > Map Document Properties > Tags.

After populating afformentioned file(s) include folder with the mxd under the Search > Search options > Index > Register Folders and Server Connections

You can also automatically update the tag field by using the code taken from https://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8 and additionally modified (appends entries to the Tags field, and have the option not to open newly created MXD)

# Author:  ESRI
# Modified: Damijan Bec
# Date:    July 5 , 2010
# Modification Date: September 6, 2016
# Version: ArcGIS 10.0
# Modified Version: ArcGIS 10.4.1
# Purpose: This script will iterate through each layer in a map document and add
#          the name of each layer as a tag value to the MXD.  The tags are
#          searchable via the search dialog and then MXDs can be identified 
#          based on the layers they contain.  The script is intended to run
#          from a script tool that requires four input parameters:
#               1) Browse to an existing MXD. (required)
#               2) Browse to and name an output MXD. (required)
#               3) Also include Group Layer names. (optional)
#               4) Open newly created MXD. (optional)

#          The resulting MXD will (if the checkbox is checked) automatically open.

import arcpy, os

try:

    # Read parameters from dialog
    mxdPath = arcpy.GetParameterAsText(0)
    outputMXD = arcpy.GetParameterAsText(1)
    includeGroupLayer = arcpy.GetParameter(2)
    openNewMXD = arcpy.GetParameter(3)

    # Reference Map Document
    mxd = arcpy.mapping.MapDocument(mxdPath)

    # Generate unique, sorted list of layer names
    layers = arcpy.mapping.ListLayers(mxd)
    layerList = []
    myWordList = []

    for lyr in layers:
        # Names of group/base layers, annotation classes are included
        if includeGroupLayer == 1:
            layerList.append(lyr.name)
        else:
            if not lyr.isGroupLayer:
                layerList.append(lyr.name)

    uniqueList = list(set(layerList))
    wordTags = [x.strip() for x in mxd.tags.split(',')]

    for word in wordTags:
        myWordList.append(word)

    # Update map document tags
    filteredList = [item for item in uniqueList if item not in myWordList]
    mergedList = filteredList + myWordList
    mergedList.sort()
    tagList = ",".join(mergedList)
    mxd.tags = tagList

    # save map document
    mxd.saveACopy(outputMXD)
    if openNewMXD == 1:
        os.startfile(outputMXD)

    del mxd

except Exception, e:
    import traceback

    map(arcpy.AddError, traceback.format_exc().split("\n"))
    arcpy.AddError(str(e))

If you want to do a batch processing use the code below.

BEWARE: Code won't allow you to create copy of the copy of MXD. E.g. It will allow you to create ArcMapDocument_tag.mxd but not ArcMapDocument_tag_tag.mxd.

There is an option to populate all existing (_tag.mxd included) MXDs though. The version below can also add Data Frame names to the Tag field. It continues if it cannot write into specific MXD file(s) because it is opened by another user (unecessary for the first script).

# Author:  ESRI
# Modified: Damijan Bec
# Date:    July 5 , 2010
# Modification Date: September 8, 2016
# Version: ArcGIS 10.0
# Modified Version: ArcGIS 10.4.1
# Purpose: This script will iterate through each layer in a map document and add
#          the name of each layer as a tag value to the MXD.  The tags are
#          searchable via the search dialog and then MXDs can be identified 
#          based on the layers they contain.  The script is intended to run
#          from a script tool that requires three input parameters:
#               1) Path to the folder with MXD files. (required)
#               2) Option to include Data frames, Group layers, Annotation classes names. (optional)
#               3) Option to populate existing MXD files. (optional)


import arcpy, os

try:

    # Read parameters from dialog
    mxdPathFolder = arcpy.GetParameterAsText(0)
    includeDataFrame = arcpy.GetParameter(1)
    overwriteExistingMXD = arcpy.GetParameter(2)

    for root, dirs, files in os.walk(mxdPathFolder):
        for name in files:
            fileName = os.path.join(root, name)
            if ".mxd" in fileName:
                # make sure that you do not end up with filename_tag_tag_tag_tag.mxd or so
                if "_tag.mxd" in fileName and overwriteExistingMXD == 0:
                    arcpy.AddMessage(
                        "You already ran this tool. There is no need to run it again. Use overwrite if you want to update all existing MXD (including *_tag.mxd) and its tags")
                else:
                    # Reference Map Document
                    mxd = arcpy.mapping.MapDocument(fileName)

                    layerList = []
                    myWordList = []

                    dataFrame = arcpy.mapping.ListDataFrames(mxd)

                    layers = arcpy.mapping.ListLayers(mxd)

                    # first loop only through data frames
                    for frame in dataFrame:
                        if includeDataFrame == 1:
                            layerList.append(frame.name)
                    # now loop also through layers and append layer names to the list
                    for lyr in layers:
                        if includeDataFrame == 1:
                            # Names of group/base layers, annotation classes are included
                            layerList.append(lyr.name)
                        else:
                            if not lyr.isGroupLayer:
                                layerList.append(lyr.name)

                    uniqueList = list(set(layerList))
                    wordTags = [x.strip() for x in mxd.tags.split(',')]

                    for word in wordTags:
                        myWordList.append(word)

                    # Update map document tags
                    filteredList = [item for item in uniqueList if item not in myWordList]
                    mergedList = filteredList + myWordList
                    mergedList.sort()
                    tagList = ",".join(mergedList)
                    mxd.tags = tagList

                    if overwriteExistingMXD == 1:
                        # save map document
                        try:
                            mxd.save()
                        except Exception, e:
                            import traceback

                            map(arcpy.AddError, traceback.format_exc().split("\n"))
                            arcpy.AddError(str(e))
                            # nice message for mere mortals that will not flee away
                            failed = "File cannot be saved as it is opened by someone else. If mxd is stored on network drive or in shared folder find who has opened it. This is the file in question: " + mxd.filePath + ". Lets continue."
                            arcpy.AddMessage(failed)

                    else:
                        fileName = fileName[:-4] + "_tag.mxd"
                        try:
                            mxd.saveACopy(fileName)
                        except Exception, e:
                            import traceback

                            map(arcpy.AddError, traceback.format_exc().split("\n"))
                            arcpy.AddError(str(e))
                            # nice message for mere mortals that will not flee away
                            failed = "File cannot be saved as it is opened by someone else. If mxd is stored on network drive or in shared folder find who has opened it. This is the file in question: " + mxd.filePath + ". Lets continue."
                            arcpy.AddMessage(failed)

                    del mxd

except Exception, e:
    import traceback

    map(arcpy.AddError, traceback.format_exc().split("\n"))
    arcpy.AddError(str(e))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.