Get Rhino background color

Hello everyone!
Nice to meet you here.

I am trying to get background color of specific rhino viewport using C#.
Here is what I already did:

1: Before I can get background color in “perspective” viewport, I have to get what display mode “perspective” is using. This is done with codes below:

A = Rhino.RhinoDoc.ActiveDoc.Views.Find(x, false).ActiveViewport.DisplayMode.DisplayAttributes.EnglishName;

2: After that I have to get backgroundstyle of “Shaded” displaymode.
I stuck here.
I searched rhinocommon online and tried a few ways. None of them asked for some input or parameter related to “shaded”. They are all somehow “global” settings.

2
3

Can anybody help me with this.
Thank you very much!

private void RunScript(string name, ref object Mode, ref object Colors)
{
  var displayMode = doc.Views.Find(name, false).ActiveViewport.DisplayMode;
  var fillMode = displayMode.DisplayAttributes.FillMode;
  Mode = fillMode;
  var colors = new Color[4];
  displayMode.DisplayAttributes.GetFill(out colors[0], out colors[1], out colors[2], out colors[3]);
  switch (fillMode)
  {
    case DisplayPipelineAttributes.FrameBufferFillMode.DefaultColor:
      Colors = Rhino.ApplicationSettings.AppearanceSettings.ViewportBackgroundColor;
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.SolidColor:
      Colors = colors[0];
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.Gradient2Color:
      Colors = new[] { colors[0], colors[1] };
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.Gradient4Color:
      Colors = colors;
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.Bitmap:
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.Renderer:
      switch (RhinoDocument.RenderSettings.BackgroundStyle)
      {
        case BackgroundStyle.SolidColor:
          Colors = RhinoDocument.RenderSettings.BackgroundColorTop;
          break;
        case BackgroundStyle.WallpaperImage:
          break;
        case BackgroundStyle.Gradient:
          Colors = new[]
            {
              RhinoDocument.RenderSettings.BackgroundColorTop,
              RhinoDocument.RenderSettings.BackgroundColorBottom
            };
          break;
        case BackgroundStyle.Environment:
          break;
        default:
          throw new ArgumentOutOfRangeException();
      }
      break;
    case DisplayPipelineAttributes.FrameBufferFillMode.Transparent:
      break;
    default:
      throw new ArgumentOutOfRangeException();
  }
}

Background.gh (4.3 KB)

1 Like

Wow!
This is super!
Thank you very much!

Hello Mahdiyar.
Your code is really helpful.
I am sorry to bother but still I have a question about overall C# development.
I found the “GetFill” in rhinocommon as link below:
Rhinocommon GetFill page
My question is how does one find the correct structure of Rhinocommon. I found the document quite unclear in structure, and with new Rhino 7 API changed a lot, online Rhinocommon is missing information in many pages.
Even in Rhino 6, Rhinocommon’s quality is a little poor for a standard developer document.
The link below is FFMpeg online document page:
FFMpeg online document
Comparing to the FFMpeg document, Rhinocommon is missing so many examples and basic workflow of the whole structure, difficult for developpers to find the command they need. In this case I found it difficult to find the correct keyword “GetFill” on my own.

I am not to criticize Rhinocommon because it is basically decent document, where I can find most keywords if I am already familiar with the structure.
But still I think something is missing in my own workflow, or there is some special technich to deal with Rhinocommon.

Thank you very much Mahdiyar.