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?

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

3 Answers 3

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.

1
  • Updated answer with tool description.
    – artwork21
    Commented Feb 27, 2015 at 14: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")
1
  • Thanks...that's great. Is this also possible with the symbology of .shp files and not only .lyr files?
    – GeorgeC
    Commented May 17, 2011 at 6:04
1

My answer to similar question Changing color of symbol in UniqueValuesSymbology object using ArcPy? :

Current answer for ArcMAP 10.8 (may be some previous versions too) is "yes, it's possible". You can use a Layer method .updateLayerFromJSON

Core part of solution is to create JSON description of layer symbology.

Code sample:

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "name*")[0]
lyr.updateLayerFromJSON(json_dictionary)

There is a valid example for polygon layer with single symbol symbology.

{"name": "pointLayer",
"geometryType": "esriGeometryPolygon",
"drawingInfo": {
       "renderer":{
       "type": "simple",
       "symbol": {
       "type": "esriSFS",
       "style": "esriSFSSolid",
       "color": [           76,           115,           0,           255          >],
       "outline": {
       "color": [            255,            0,            0,            255           >],
       "width": 1          }}}}}

Above code is a value of tag layerDefinition from this specification: >https://enterprise.arcgis.com/ru/server/10.8/create-web-apps/windows/exportwebmap->specification.htm#ESRI_SECTION1_FC212A2B579B425A9FE4358ACC89482A

Details about specification can be found here: https://developers.arcgis.com/web->map-specification/objects/renderer/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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