0

I'm using a python script to create an empty group layer in the current map document, add some layers to this group and update their symbology from an existing .lyr file.

I also want to to turn on these layers' labels using layer.showLabels = True and it works fine for normal layers, but for some reason it doesn't work on layers inside a group layer. However, when I manually drag these layers outside of the group, the labels are suddenly displayed, and they are still displayed when I drag the layers back into the group.

Does anyone has an idea why does it happen and how can I programmatically display the labels even for layers inside a group?

Thanks.

Edit:

Here is the relevant part (of a simplified version) of my ode:

mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
groupLyr = arcpy.mapping.Layer(r'C:\Path\to\Group.lyr') # this is an empty group lyr file

arcpy.mapping.AddLayer(df,groupLyr)
currentGroup = arcpy.mapping.ListLayers(mxd,"Group")[0]

source_fc = arcpy.mapping.Layer(r'C:\Path\to\my.gdb\feature_class')
arcpy.mapping.AddLayerToGroup(df, currentGroup, source_fc, "BOTTOM")

lyr = arcpy.mapping.ListLayers(mxd,"[my layer's name]")[0]
lyr.showLabels = True # this line doesn't raise an error, but it does not turns the labels on
  • Would you be able to edit your question to include a code snippet that works up to where you are stuck, please? – PolyGeo Oct 22 '14 at 11:59
  • Of course. I added the relevant parts of the code, but I don't think the problem is caused by the script. It seems to me like an ArcMap problem. – isshp Oct 22 '14 at 12:59
  • Could you let us know the version you are using too - I have a vague recollection of a problem in this vicinity so knowing your version may help my searching. – PolyGeo Oct 22 '14 at 13:14
  • I am using ArcGIS 10.1 Basic with SP1. – isshp Oct 22 '14 at 13:37
  • Do you actually have 'my layer's name' in brackets, or is that just for illustration? You may also want to add df to the Listlayers call. – recurvata Oct 22 '14 at 13:50

Your Answer

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

Browse other questions tagged or ask your own question.