ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Arcade Namespace / ArcadeScriptEngine Class / CreateEvaluator Method
Example Version

CreateEvaluator Method (ArcadeScriptEngine)
Creates an instance of an Arcade script evaluator. This method must be called on the MCT. Use QueuedTask.Run.
Syntax

Parameters

expressionInfo
profile

Return Value

Exceptions
ExceptionDescription
 
Exception thrown when there has been a parsing error
This method or property must be called within the lambda passed to QueuedTask.Run.
Example
var expressionInfo = new CIMExpressionInfo()
{
  Expression = "$feature.objectid",
  ExpressionReturnType = CIMExpressionReturnType.String
};
            
try
{
  using (var arcade = ArcadeScriptEngine.Instance.CreateEvaluator(expressionInfo, ArcadeProfile.Visualization))
  {
  
  }
}
catch (ParsingException ex)
{
  System.Diagnostics.Trace.WriteLine(ex);
}
Basic Query
//Consult https://github.com/Esri/arcade-expressions/ and
//https://developers.arcgis.com/arcade/ for more examples
//and arcade reference

QueuedTask.Run(() =>
{
  //construct an expression
  var query = @"Count($layer)";//count of features in "layer"

  //construct a CIMExpressionInfo
  var arcade_expr = new CIMExpressionInfo()
  {
    Expression = query.ToString(),
    //Return type can be string, numeric, or default
    //When set to default, addin is responsible for determining
    //the return type
    ReturnType = ExpressionReturnType.Default
  };

  //Construct an evaluator
  //select the relevant profile - it must support Pro and it must
  //contain any profile variables you are using in your expression.
  //Consult: https://developers.arcgis.com/arcade/profiles/
  using (var arcade = ArcadeScriptEngine.Instance.CreateEvaluator(
                          arcade_expr, ArcadeProfile.Popups))
  {
    //Provision  values for any profile variables referenced...
    //in our case '$layer'
    var variables = new List<KeyValuePair<string, object>>() {
        new KeyValuePair<string, object>("$layer", featLayer)
      };
    //evaluate the expression
    try
    {
      var result = arcade.Evaluate(variables).GetResult();
      System.Diagnostics.Debug.WriteLine($"Result: {result.ToString()}");
    }
    //handle any exceptions
    catch (InvalidProfileVariableException ipe)
    {
      //something wrong with the profile variable specified
      //TODO...
    }
    catch (EvaluationException ee)
    {
      //something wrong with the query evaluation
      //TODO...
    }

  }
});
Basic Query using Features
//Consult https://github.com/Esri/arcade-expressions/ and
//https://developers.arcgis.com/arcade/ for more examples
//and arcade reference

QueuedTask.Run(() =>
{
  //construct an expression
  var query = @"$feature.AreaInAcres * 43560.0";//convert acres to ft 2

  //construct a CIMExpressionInfo
  var arcade_expr = new CIMExpressionInfo()
  {
    Expression = query.ToString(),
    //Return type can be string, numeric, or default
    //When set to default, addin is responsible for determining
    //the return type
    ReturnType = ExpressionReturnType.Default
  };

  //Construct an evaluator
  //select the relevant profile - it must support Pro and it must
  //contain any profile variables you are using in your expression.
  //Consult: https://developers.arcgis.com/arcade/profiles/
  using (var arcade = ArcadeScriptEngine.Instance.CreateEvaluator(
                          arcade_expr, ArcadeProfile.Popups))
  {
    //we are evaluating the expression against all features
    using (var rc = featLayer.Search())
    {

      while (rc.MoveNext())
      {
        //Provision  values for any profile variables referenced...
        //in our case '$feature'
        var variables = new List<KeyValuePair<string, object>>() {
          new KeyValuePair<string, object>("$feature", rc.Current)
        };
        //evaluate the expression (per feature in this case)
        try
        {
          var result = arcade.Evaluate(variables).GetResult();
          var val = ((double)result).ToString("0.0#");
          System.Diagnostics.Debug.WriteLine(
            $"{rc.Current.GetObjectID()} area: {val} ft2");
        }
        //handle any exceptions
        catch (InvalidProfileVariableException ipe)
        {
          //something wrong with the profile variable specified
          //TODO...
        }
        catch (EvaluationException ee)
        {
          //something wrong with the query evaluation
          //TODO...
        }
      }
    }
  }
});
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3.2 or higher.
See Also