I try to count how many times the layer "frame" occurs in 3 MXD files.
The layer "frame" (this is the layer name in the table of contents) occur in "project1" (this is the first MXD file)- 1 time.
In "project2"- it occur 2 times.
In "project3"- it occur 3 times.
I'm using this python code:
import arcpy,os,sys,string
import arcpy.mapping
from arcpy import env
env.workspace = r"G:\desktop\Project"
counter = 0
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"G:\desktop\Project\\" + mxdname)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
dfList = arcpy.mapping.ListDataFrames(mxd, "*")
for df in dfList:
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "frame":
counter = counter + 1
print counter
mxd.save()
del mxd
But i get this incorrect result:
>>>
project1.mxd
1
project2.mxd
4
project3.mxd
6
>>>
What am I doing wrong?