ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMLabelClass Class / Expression Property
Example

In This Topic
    Expression Property (CIMLabelClass)
    In This Topic
    Gets or sets the label expression.
    Syntax
    Public Property Expression As String
    public string Expression {get; set;}
    Example
    Modify label expression using Arcade
    {
      // Note: the following should be embedded in a QueuedTask.Run() statement
      {
        //Get the layer's definition, using the community sample Data\Admin\AdminSample.aprx
        if (featureLayer.GetDefinition() is not CIMFeatureLayer lyrDefn)
        {
          // not a feature layer, leave
          return;
        }
        //Get the label classes - we need the first one
        var listLabelClasses = lyrDefn.LabelClasses.ToList();
        var theLabelClass = listLabelClasses.FirstOrDefault();
        //set the label class Expression to use the Arcade expression
        theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;";
        //Set the label definition back to the layer.
        featureLayer.SetDefinition(lyrDefn);
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also