ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / StyleHelper Class / SearchColorRamps Method
The StyleProjectItem to search.
The search term.
Example

In This Topic
    SearchColorRamps Method
    In This Topic
    Returns a collection of color ramp style items that satisfy the search criteria. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    styleProjectItem
    The StyleProjectItem to search.
    searchString
    The search term.

    Return Value

    A collection of ColorRampStyleItem.
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run
    Example
    How to search for color ramps in a style
    {
        //StyleProjectItem can be "ColorBrewer Schemes (RGB)", "ArcGIS 2D"...
        //Search for color ramps
        //Color Ramp searchString can be "Spectral (7 Classes)", "Pastel 1 (3 Classes)", "Red-Gray (10 Classes)"..
        styleProjectItem.SearchColorRamps("searchString");
    }
    How to apply a color ramp from a style to a feature layer
    {
        List<string> fields = new List<string>() { "Field1" };
        //Note: Needs QueuedTask to run
        StyleProjectItem styleToUse =
          Project.Current.GetItems<StyleProjectItem>()
              .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        //Note: Needs QueuedTask to run
        var colorRampListFound = styleToUse.SearchColorRamps("Red-Gray (10 Classes)");
        if (colorRampListFound == null || colorRampListFound.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
    
        cimColorRamp = colorRampListFound[0].ColorRamp;
        var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
        renderer = featureLayer?.CreateRenderer(rendererDef);
        featureLayer?.SetRenderer(renderer);
    }
    Create a feature layer with class breaks renderer
    {
        string colorBrewerSchemesName = "ColorBrewer Schemes (RGB)";
        StyleProjectItem colorBrewerStyle = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
        string colorRampName = "Greens (Continuous)";
        //Note: Needs QueuedTask to run
        IList<ColorRampStyleItem> colorRampListFromTheStyle = colorBrewerStyle.SearchColorRamps(colorRampName);
    
        ColorRampStyleItem colorRampFound = colorRampList[0];
        GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
        {
            ClassificationField = "CROP_ACR07",
            ClassificationMethod = ArcGIS.Core.CIM.ClassificationMethod.NaturalBreaks,
            BreakCount = 6,
            ColorRamp = colorRampFound.ColorRamp,
            SymbolTemplate = SymbolFactory.Instance.ConstructPolygonSymbol(
                                  ColorFactory.Instance.GreenRGB, SimpleFillStyle.Solid, null).MakeSymbolReference(),
            ExclusionClause = "CROP_ACR07 = -99",
            ExclusionSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(
                                  ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, null).MakeSymbolReference(),
            ExclusionLabel = "No yield",
        };
        var featureLayerCreationParams = new FeatureLayerCreationParams((new Uri(@"c:\Data\CountyData.gdb\Counties")))
        {
            Name = "Crop",
            RendererDefinition = gcDef
        };
        //Note: Needs QueuedTask to run
        LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerCreationParams, MapView.Active.Map);
    }
    Create and Set a Stretch Renderer
    {
      // Note: call within QueuedTask.Run()
      {
        var fields = pointCloudSceneLayer.GetAvailablePointCloudRendererFields(
                                PointCloudRendererType.StretchRenderer);
        var stretchDef = new PointCloudRendererDefinition(
                                  PointCloudRendererType.StretchRenderer)
        {
          //Will be either ELEVATION or INTENSITY
          Field = fields[0]
        };
        //Create the CIM Renderer
        var stretchRenderer = pointCloudSceneLayer.CreateRenderer(stretchDef)
                                            as CIMPointCloudStretchRenderer;
        //Apply a color ramp
        var style = Project.Current.GetItems<StyleProjectItem>()
                                        .First(s => s.Name == "ArcGIS Colors");
        var colorRamp = style.SearchColorRamps("").First();
        stretchRenderer.ColorRamp = colorRamp.ColorRamp;
        //Apply modulation
        stretchRenderer.ColorModulation = new CIMColorModulationInfo()
        {
          MinValue = 0,
          MaxValue = 100
        };
        //apply the renderer
        pointCloudSceneLayer.SetRenderer(stretchRenderer);
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also