1

I have some substances TPH, CO2, SO2, VOC, analyzed in a period of time 2001 - 2017. In the .mxd each year is a group layer, containing all the substances for that year:

2001: - TPH

  - CO2

  - SO2

  - VOC

2002 - TPH

  - CO2

  - SO2

  - VOC

...until 2017

I want to apply the same symbology for TPH substance in 2001, 2002, 2003 etc. I have made .lyr files for all the substances, but I have managed to write a functional code to apply one symbology for all layers in the same group layer.

Any solution to apply the same symbology for just one layer in all the group layers?

I have many more substances than the ones mentioned!

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

df = mxd.activeDataFrame

groupName = "2001"

allLayers = arcpy.mapping.ListLayers(mxd, groupName, df) [0]

for layer in allLayers: 

    arcpy.ApplySymbologyFromLayer_management(layer, "TPH")

PS: I use ArcMap 10.6 and the batch function for the Apply Symbology From Layer tool is not working

  • So for example symbol for 2001-CO2 should be applied to all years CO2 layers? – BERA Nov 26 '18 at 14:17
  • yes, I apply the same threshold values – Adriana Popa Nov 26 '18 at 14:55
2

Apply your symbols to all layers in one Group (named template_group below) then try code below. It will match by layer name and apply the same symbology as the layers in the template Group:

import arcpy

template_group = '2001' #Change to match your group with the symbolized layers
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
template_layers = {l.name:l for l in arcpy.mapping.ListLayers(arcpy.mapping.ListLayers(mxd,template_group)[0]) if not l.isGroupLayer} #Create a Dictionary of layer name as key and layer as value

other_groups = [g for g in arcpy.mapping.ListLayers(mxd) if (g.isGroupLayer and g.name!=template_group)]

for group in other_groups:
    layers = [l for l in arcpy.mapping.ListLayers(arcpy.mapping.ListLayers(mxd,group)[0]) if not l.isGroupLayer]
    for lyr in layers:
        if lyr.name in template_layers:
            arcpy.ApplySymbologyFromLayer_management(in_layer=lyr, 
                                                    in_symbology_layer=template_layers[lyr.name])

enter image description here

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.