I have 4 mxd's and I want to insert layer file to each mxd with position in the TOC. Each mxd has 3 and more data frame. I don't know why it does't work. I'm trying this code:
import arcpy,os,sys
from arcpy import env
env.workspace = r"F:\Projects\Guy\mikta3\gis"
for mxdname in arcpy.ListFiles("*.mxd"):
mxd = arcpy.mapping.MapDocument(r"F:\Projects\Guy\mikta3\gis\\" + mxdname)
refLayer = arcpy.mapping.ListLayers(mxd, "roads", df)[0] # as display in TOC
insertLayer = arcpy.mapping.Layer(r"F:\Projects\Guy\mikta3\gis\layers\residence.lyr")
dfList = arcpy.mapping.ListDataFrames(mxd, "*")
for df in dfList:
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
arcpy.mapping.InsertLayer(df, refLayer, insertLayer, "AFTER") # BEFORE\ AFTER
mxd.save()
del mxd