0

I want to apply layer symbology to all TIFF in a group layer but it does not work:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
groupName = "New Group Layer-s"
lyrFile = "G:\work insar\1402mehr1402\LAYER\Mahad2.lyr"
allLayers = arcpy.mapping.ListLayers(mxd, groupName, df)[0]
 for layer in allLayers:
   arcpy.ApplySymbologyFromLayer_management(layer, lyrFile)
   layer.visible = "True"
arcpy.RefreshActiveView()
1
  • In what way does your code not work? Does it give you an error message? If, please include that in your question.
    – PolyGeo
    Commented Sep 18, 2023 at 19:33

2 Answers 2

0

hi i do not know why but now it workes `enter code here

  import arcpy

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

  df = mxd.activeDataFrame

  groupName = "New Group Layer-s"

  lyrFile = "mahad2.tif"

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

    for layer in allLayers:

    arcpy.ApplySymbologyFromLayer_management(layer, lyrFile)
    layer.visible = "True"
 arcpy.RefreshActiveView()
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Sep 19, 2023 at 7:56
0

There are two things wrong with your code:

  1. You have used the group layer name as the wildcard parameter in Listlayers(). So what's the only thing in your mxd with that name... your group layer so that's what is returning a group layer.
  2. You end your line with [0]. That is telling Python to return the first thing in the list so your next line is incorrect as allLayers is not a list object that you can use a for loop on.

So as it stands allLayers is a group layer object and not a list of layers. You need to read the help file and understand how to step over a group layer to drill down to the layers in it. There will probably be examples if you search this forum.

0

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.