Import lyr file to entire project

737
2
04-08-2011 02:27 AM
PatrãoPedro
New Contributor
Hello to all,

Does anyone have or can point me in the right direction were to find a piece of code that allow's you to import a lyr file to an entire project or to a defined group layer?

Thanks in advance
Patrao
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Here is an example on how to add the layer file to your current MXD:

import arcpy
from arcpy import mapping

mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd, "Layers")[0]
addLayer = arcpy.mapping.Layer(r"C:\DATA\PA_DEM.lyr")

mapping.AddLayer(df, addLayer)

arcpy.RefreshTOC()
arcpy.RefreshActiveView()


Here is an example on how to add the layer file to a particular group layer in your current MXD:

import arcpy
from arcpy import mapping

mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd, "Layers")[0]

targetGroupLayer = mapping.ListLayers(mxd, "L00 (147,748K)", df)[0]
addLayer = mapping.Layer(r"C:\DATA\PA_DEM.lyr")
mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")

arcpy.RefreshTOC()
arcpy.RefreshActiveView()
0 Kudos
PatrãoPedro
New Contributor
Hi,

Thanks for the code but I think I didn�??t explain myself very well.
What I meant was importing a raster symbology lyr file. I have about 200 rasters that I made using model builder and I need to uniform all classification intervals. When I use the model builder to produce rasters from kriging they always come out  in the form of stretched  with values differing in each raster, which usually I have to import the symbology lyr file one by one.
So what I�??m looking for is a way, which I think only code will solve, to make possible importing the symbology (lyr) file to the rest of the rasters in the project, or a group layer giving them all the same classification values making them more comparable.

Thanks in advance for any help
Cheers
Patrao
0 Kudos