HOW TO

Enable the visibility of a specific sublayer in a group layer using Python script in ArcGIS Pro

Last Published: July 16, 2021

Summary

A sublayer inherits the visibility of its group layer, hence, any attempt to enable the visibility of the sublayer does not work if the group layer is marked as invisible. The instructions provided describe how to display the desired sublayer in a set of group layers using Python when the visibility for the group layer is disabled.

Procedure

The following is the script to disable the visibility of the parent group layers without affecting the visibility of the selected sublayer. Defining the parameter of the layer.longName method as the desired sub-layer retains the visibility of the selected sublayer.

  1. In ArcGIS Pro, click the Analysis tab on the top ribbon. Click the drop-down menu next to Python, and select Python window.
  2. In the Python window, insert the following commands:
import arcpy
aprx = arcpy.mp.ArcGISProject("Current")
m = aprx.listMaps("Map")[0]
layers = m.listLayers('Layers')

for layer in layers:
    layer.visible = True
    if layer.longName == "Group Name\SubLayer Name":
       layer.visible = True
  1. Press Enter.

Article ID:000025761

Software:
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic