What is the Display Field in ArcGIS Pro?
The display field in ArcGIS Pro is a layer property that uses a designated attribute field used to identify features in various contexts, such as editing tools, selection chips, MapTips, Pop-ups, and published map services. It is typically set to a field that provides a meaningful identifier for the features, such as a name or ID.
You can manually adjust the display field by:
GIF showing how to change the display field
What if you want to update the display field for every layer, all at once?
To automate the process of updating the display field, users can open the Python window in ArcGIS Pro and run a short script. How do you open the Python window?
GIF showing how to open the Python Window in ArcGIS Pro
Below is a script you can run to update the display field for every layer on your map. Just remember to change line #9 to whatever field you would like to use 😎.
#import arcpy library
import arcpy
# Define your project and map
project = arcpy.mp.ArcGISProject("CURRENT")
map = project.listMaps()[0]
# Define the display field you want to set
display_field = "FID"
# Loop through all layers and set the display field
for layer in map.listLayers():
if layer.isFeatureLayer:
# Get the layer's CIM definition
cim_layer = layer.getDefinition('V2')
# Update the display field
cim_layer.featureTable.displayField = display_field
# Apply the updated CIM definition back to the layer
layer.setDefinition(cim_layer)
# Save changes
project.save()
Let's break down the script:
Importing the arcpy Module
import arcpy
The script begins by importing the ArcPy module, which is essential for accessing ArcGIS Pro functionalities.
Defining the Project and Map
project = arcpy.mp.ArcGISProject("CURRENT")
map = project.listMaps()[0]
Here, we define the current project and select the first map in the project. This sets the context for the layers we want to modify.
Setting the Display Field
display_field = "FID"
We specify the display field we want to set for all feature layers. In this case, it's the FID field, but you can make this your ObjectID or a different identifying field.
Looping Through Layers
for layer in map.listLayers():
if layer.isFeatureLayer:
# Get the layer's CIM definition
cim_layer = layer.getDefinition('V2')
# Update the display field
cim_layer.featureTable.displayField = display_field
# Apply the updated CIM definition back to the layer
layer.setDefinition(cim_layer)
This loop iterates through all layers in the map. For each feature layer, it retrieves the layer's CIM (Cartographic Information Model) definition, updates the display field, and applies the changes.
Saving Changes
project.save()
By leveraging Python scripting, you can automate the process of updating display fields across multiple layers, significantly enhancing your workflow and productivity. Embrace the power of automation to optimize your GIS tasks and achieve better results in less time!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.