Select to view content in your preferred language

Add ArcGIS Pro Layer Properties Class to Python

93
1
3 weeks ago
Status: Open
Labels (1)
SavageTrimble
Emerging Contributor

We need to update python library for ArcGIS API to support properties for each layer in the Table of Contents.  For example, I want to set a display field to a common field for every layer within the Table of Contents within the ArcGIS Pro Map.  if I have a variable that looks at listLayers called lyr.  We should be able to get to the properties of each item for that layer and update the values.  lyr.Properties.Display.DisplayField('uid') or lyr.Properties.Display.Scalesymbols('True')

1 Comment
JesseWickizer

You can update the layer properties with Python CIM access. All of the layer's properties are accessible through the Cartographic Information Model (CIM), and you can use the arcpy.mp Layer class' getDefinition() method to retrieve the layer's CIM definition, make changes, then push the changes back to the layer using the setDefinition() method.

Here's an example of setting the 2 properties you noted:

aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps('Map')[0]               #Get first Map named Map
lyr = map.listLayers('Point')[0]            #Get first layer in the map named Point

l_cim = lyr.getDefinition('V3')             #Get Layer CIM definition

#Update some CIM properties:
l_cim.scaleSymbols = True                   #'Scale symbols when a reference scale is set' property
l_cim.featureTable.displayField = "Notes"   #'Display field' property

lyr.setDefinition(l_cim)                    #Set the Layer's updated CIM definition