Add layer from one datar frame to others in same .mxd

1839
3
05-06-2014 07:05 PM
RossRomero
New Contributor
I need to write a script that adds the parks layer from the parks data frame in the Austin_TX.mxd (attached)to the other two data frames in the same map document.

Any help would be greatly appreciated. I know this is a very easy script, but I cant seem to wrap my mind around doing it.
Tags (2)
0 Kudos
3 Replies
Zeke
by
Regular Contributor III
You want to use InsertLayer. Give that a try and post back with any problems you have.
0 Kudos
RossRomero
New Contributor
This is what I've come up with so far. I don't know how to add that layer to the other two data frames in the Austin_TX.mxd file.




import arcpy
mxd = arcpy.mapping.MapDocument(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Parks")[0]
addLayer = arcpy.mapping.Layer(r"parks.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.saveACopy(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd")
del mxd, addLayer
0 Kudos
Zeke
by
Regular Contributor III
Well, that's not using InsertLayer. There's a good example at the link I provided. Anyway, if you want to use AddLayer. change this:


df = arcpy.mapping.ListDataFrames(mxd, "Parks")[0]

to this:

df = arcpy.mapping.ListDataFrames(mxd, "Parks")[1]

and so on. the [0] refers to your first data frame. [1] is the second, [2] is the third, etc.
You can call the function twice, or put it in a loop something like:




import arcpy 
mxd = arcpy.mapping.MapDocument(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd") dfList = arcpy.mapping.ListDataFrames(mxd, "Parks") addLayer = arcpy.mapping.Layer("parks.lyr")

for df in dfList:     
    arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.saveACopy(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd") del mxd, addLayer
0 Kudos