AnsweredAssumed Answered

Search layer in mxd's using Python

Question asked by yaron148 on Dec 21, 2015
Latest reply on Dec 22, 2015 by Dan_Patterson


I work with ArcGIS 10.3 and I try to search a specific layer (with data Source named "D:\desktop\Project\layers\1.jpg" ) in hundred of mxd's that spread in folder "D:\PROJECTS" and it divided to hundred of sub folders. I using python 2.7.8:


import arcpy,os,sys
import arcpy.mapping
from arcpy import env

env.workspace = r"D:\desktop\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
    mxd = arcpy.mapping.MapDocument(r"D:\desktop\Project\\" + mxdname)
    dfList = arcpy.mapping.ListDataFrames(mxd, "*")
    for df in dfList:
        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
            if lyr.isGroupLayer == True: continue                                   
            if lyr.dataSource == r"D:\desktop\Project\layers\1.jpg":
                print mxdname, mxdname.pathway
del mxd


Finally, I want that python will print all the mxd's source name that contain the specific layer I search for. When I run the code I get error:



Traceback (most recent call last):
File "C:\Users\yaron.KAYAMOT\Desktop\idle.pyw", line 13, in <module>
print mxdname, mxdname.pathway
AttributeError: 'unicode' object has no attribute 'pathway'


Doe's anyone have a solution for this issue?

For clarity, i ask it in arcpy - Search MXDs with specific dataSource layer using Python - Geographic Information Systems Stack Exchange