3

I have this layer structure in ArcMap:

enter image description here

"Localities, Gazeteers, Bases, Regions, and Territorial Claims are all Group Layers. All others under these are layers. I have a script that uses the Arcpy Describe method to go under each layer and get its full directory path. Here is the script:

import arcpy
mxd=arcpy.mapping.MapDocument("CURRENT")
dataframes=arcpy.mapping.ListDataFrames(mxd)
for dataframe in dataframes:
    for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
        if not lyr.isGroupLayer:    
            print(arcpy.Describe(lyr).catalogPath)

This would return something like: C:/Folder/Subfolder/layer.shp Now, I am trying to figure out a way to get the path of each layer relative to the map. For example, for layer "features_multipoint", I need the script to report something like this:

MapDocument/Localities/Gazeteers/features_multipoint

The Describe method seems to not provide such capabilities.

11

Try lyr.longName

longName (Read Only)

This property is valuable when trying to determine whether a layer belongs to a group layer. If a layer does not belong to a group layer, the long name will equal the layer name. If a layer does belong to a group layer, the group layer structure will be included in the long name. For example, the name of a layer nested inside a group layer within another group layer may look something like Group1\Group2\LayerName. All layer types support this property.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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