Is This Content Helpful?
We're glad to know this article was helpful.
Users are unable to view the desired sublayer in a set of group layers after toggling off the visibility for the parent group layer using Python.
The following code section allows the user to toggle the visibility of the parent group layers without affecting the visibility of the selected sub-layer. By defining the parameter of the method layer.longName as the desired sub-layer, users can retain the visibility of the selected sub-layer.
import arcpy mxd = arcpy.mapping.MapDocument("current") data_frame = arcpy.mapping.ListDataFrames(mxd, "Layers") layers = arcpy.mapping.ListLayers(mxd) for layer in layers: if layer.isGroupLayer: layer.visible = True if layer.longName =="Group Name\SubLayer Name": layer.visible = True arcpy.RefreshTOC() arcpy.RefreshActiveView()
mxd = arcpy.mapping.MapDocument("current")with the Windows directory location of the MXD:
mxd = arcpy.mapping.MapDocument("C:\ C:\Users\UserName\Documents\TestFiles")