Listing feature classes that are in use by an mxd

7141
2
Jump to solution
11-05-2012 05:51 AM
JesseMorkis
New Contributor II
I am trying to get a list of all feature classes that are in use by an mxd using a python script. I can access the map document through arcpy.mapping and list all of the layers, but I am having a difficult time listing the feature classes that are being used. The layer names within the map document have been changed from the original feature class, so listlayers does not give me an accurate description of the actual feature classes in use. If anyone has an idea of how to do this through a script it would be greatly appreciated. It is a simple script, where I want to create a list of feature classes in use by the mxd and copy them out to an xls file, but this one little thing is holding me up.

Thanks,

Jesse
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BruceBacia
Occasional Contributor
You should be able to run this script from idle.  Just substitute the path to your mxd.  You might have to tweak this some if the mxd has multiple data frames or grouped layers


from arcpy import mapping mapDoc = r'enter mxd file path here' mxd = mapping.MapDocument(mapDoc) lyrs = mapping.ListLayers(mxd) lyrTitle = 'Map Layer' sourceTitle = 'Data Source' print('%-60s%s' % (lyrTitle,sourceTitle)) print('%-60s%s' % ('-' * len(lyrTitle), '-' * len(sourceTitle))) for lyr in lyrs:     try:         print('%-60s%s' % (lyr.name,lyr.dataSource))     except:         print('Unable to retrieve layer information') del mxd

View solution in original post

2 Replies
BruceBacia
Occasional Contributor
You should be able to run this script from idle.  Just substitute the path to your mxd.  You might have to tweak this some if the mxd has multiple data frames or grouped layers


from arcpy import mapping mapDoc = r'enter mxd file path here' mxd = mapping.MapDocument(mapDoc) lyrs = mapping.ListLayers(mxd) lyrTitle = 'Map Layer' sourceTitle = 'Data Source' print('%-60s%s' % (lyrTitle,sourceTitle)) print('%-60s%s' % ('-' * len(lyrTitle), '-' * len(sourceTitle))) for lyr in lyrs:     try:         print('%-60s%s' % (lyr.name,lyr.dataSource))     except:         print('Unable to retrieve layer information') del mxd
JesseMorkis
New Contributor II
Thanks Bruce, that was exactly what I needed.
0 Kudos