ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ColorFactory Class / GenerateColorsFromColorRamp Method
The color ramp to use to generate the colors
The number of colors to generate
Example

In This Topic
    GenerateColorsFromColorRamp Method (ColorFactory)
    In This Topic
    Generate a list of [count] colors from the specified color ramp. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GenerateColorsFromColorRamp( _
       ByVal colorRamp As CIMColorRamp, _
       ByVal count As Integer _
    ) As List(Of CIMColor)
    public List<CIMColor> GenerateColorsFromColorRamp( 
       CIMColorRamp colorRamp,
       int count
    )

    Parameters

    colorRamp
    The color ramp to use to generate the colors
    count
    The number of colors to generate

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    colorRamp
    count must be greater than zero
    Example
    Create and Set a ClassBreaks Renderer
    {
      // Note: call within QueuedTask.Run()
      {
        var fields = pointCloudSceneLayer.GetAvailablePointCloudRendererFields(
                           PointCloudRendererType.ClassBreaksRenderer);
        var classBreakDef = new PointCloudRendererDefinition(
                                  PointCloudRendererType.ClassBreaksRenderer)
        {
          //ELEVATION or INTENSITY
          Field = fields[0]
        };
        //create the renderer
        var cbr = pointCloudSceneLayer.CreateRenderer(classBreakDef)
                                  as CIMPointCloudClassBreaksRenderer;
        //Set up a color scheme to use
        var style = Project.Current.GetItems<StyleProjectItem>()
                                   .First(s => s.Name == "ArcGIS Colors");
        var rampStyle = style.LookupItem(
          StyleItemType.ColorRamp, "Spectrum By Wavelength-Full Bright_Multi-hue_2")
                                                                    as ColorRampStyleItem;
        var colorScheme = rampStyle.ColorRamp;
        //Set up 6 manual class breaks
        var breaks = 6;
        var colors = ColorFactory.Instance.GenerateColorsFromColorRamp(
                                                    colorScheme, breaks);
        var classBreaks = new List<CIMColorClassBreak>();
        var min = cbr.Breaks[0].UpperBound;
        var max = cbr.Breaks[cbr.Breaks.Count() - 1].UpperBound;
        var step = (max - min) / (double)breaks;
    
        //add in the class breaks
        double upper = min;
        for (int b = 1; b <= breaks; b++)
        {
          double lower = upper;
          upper = b == breaks ? max : min + (b * step);
          var cb = new CIMColorClassBreak()
          {
            UpperBound = upper,
            Label = string.Format("{0:#0.0#} - {1:#0.0#}", lower, upper),
            Color = colors[b - 1]
          };
          classBreaks.Add(cb);
        }
        cbr.Breaks = classBreaks.ToArray();
        pointCloudSceneLayer.SetRenderer(cbr);
      }
    }
    How to Change Value and Color on an Isosurface
    {
      // Note: call within QueuedTask.Run()
      {
        var variable = voxelLayer.SelectedVariableProfile;
    
        //Change the color of the first surface for the given profile
        var surface = variable.GetIsosurfaces().FirstOrDefault();
        if (surface != null)
        {
          if (voxelLayer.Visualization != VoxelVisualization.Surface)
            voxelLayer.SetVisualization(VoxelVisualization.Surface);
    
          //Change the iso surface voxel value
          surface.Value = surface.Value * 0.9;
    
          //get a random color
          var count = new Random().Next(0, 100);
          var colors = ColorFactory.Instance.GenerateColorsFromColorRamp(
            ((CIMVoxelStretchRenderer)variable.Renderer).ColorRamp, count);
    
          var idx = new Random().Next(0, count - 1);
          surface.Color = colors[idx];
          //set the custom color flag true to lock the color
          //locking the color prevents it from being changed if the
          //renderer color range or color theme is updated
          surface.IsCustomColor = true;
    
          //update the surface
          variable.UpdateIsosurface(surface);
        }
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also