5

In an active ArcMap session - I want to change the symbology of a layer which is repeated multiple times in the mxd. Can I do this?

The basic code I have for getting the layers is below. This is running within ArcMap (not as a .py script)

myMXD = arcpy.mapping.MapDocument("Current")
lstDataFrames=arcpy.mapping.ListDataFrames(myMXD)
lstLayers=arcpy.mapping.ListLayers(myMXD)

hazardLayer=arcpy.mapping.ListLayers(myMXD,'*Haz*')

allFrames=arcpy.mapping.ListDataFrames(myMXD)

for dataFrame in allFrames:
    myMXD.activeView=dataFrame
    for mapLayer in hazardLayer:
        mapLayer.visible=False

This just changes the visibility to off...can I change the color for example to some RGB value?

  • GeogeC,what the sign Haz with the 2 Asterisk mean? – newGIS Mar 29 '15 at 7:08
7

First create a default layer file to use as a template then:

myMXD = arcpy.mapping.MapDocument("Current")
lstDataFrames=arcpy.mapping.ListDataFrames(myMXD)
lstLayers=arcpy.mapping.ListLayers(myMXD)

hazardLayer=arcpy.mapping.ListLayers(myMXD,'*Haz*')

allFrames=arcpy.mapping.ListDataFrames(myMXD)

for dataFrame in allFrames:
     myMXD.activeView=dataFrame
     for mapLayer in hazardLayer:
         arcpy.ApplySymbologyFromLayer_management(mapLayer, r"C:\TemplateLayers\HazardTemplate.lyr")
  • Thanks...that's great. Is this also possible with the symbology of .shp files and not only .lyr files? – GeorgeC May 17 '11 at 6:04
9

You could use the Apply Symbology From Layer tool.

This tool applies the symbology from a layer to the Input Layer. It can be applied to feature, raster, network analysis, TIN, and geostatistical layer files or layers in the ArcMap table of contents. This tool is primarily for use in scripts or ModelBuilder.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Updated answer with tool description. – artwork21 Feb 27 '15 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.