How to set gradient 2 colors background

Hi,
My system is Rhino 6 C++ SDK.
I want to design custom view background in my plugin.
How to set the Display mode to Rendered and set the Background to Gradient 2 Colors by API function at CMyRhinoEventWatcher::OnInitRhino ?

Hi @john12,

Rather than modify Rhino’s Rendered display mode, you might consider making a copy of it and modifying it to your liking. Then, when the user opens a new file, set the custom display mode to whatever view’s you want.

Does this help?

– Dale

Hi,
This is my code.

ON_UUID display_id = ON_StandardDisplayModeId::Rendered;
CRhinoView* pView = RhinoApp().ActiveView();
pView->ActiveViewport().SetDisplayMode(display_id);
pView->Redraw();

This result is to set Display mode to Render.
But I don’t know how to set Background to Gradient 2 Colors, Top, and Bottom color.
Please give me a sample.

Hi @john12,

From a command you can do something like this:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  const ON_UUID display_mode = ON_StandardDisplayModeId::Rendered;
  DisplayAttrsMgrListDesc* pDisplayAttrs = CRhinoDisplayAttrsMgr::FindDisplayAttrsDesc(display_mode);
  if (nullptr != pDisplayAttrs)
  {
    CDisplayPipelineAttributes* pAttrs = pDisplayAttrs->m_pAttrs;
    if (nullptr != pAttrs)
    {
      pAttrs->m_eFillMode = EFrameBufferFillMode::FBFM_GRADIENT_2_COLOR;
      pAttrs->m_GradTopLeft = RGB(0, 50, 102);
      pAttrs->m_GradBotLeft = RGB(165, 165, 165);
      pAttrs->m_GradTopRight = pAttrs->m_GradTopLeft;
      pAttrs->m_GradBotRight = pAttrs->m_GradBotLeft;
      CRhinoDisplayAttrsMgr::UpdateAttributes(*pDisplayAttrs);
      CRhinoDisplayAttrsMgr::SaveProfile(RhinoApp().ProfileContext());
      context.m_doc.Regen();
    }
  }
  return CRhinoCommand::success;
}

– Dale

Hi @dale ,

How to implement this code in python?

Thanks

This should do it:

import System
import Rhino
import scriptcontext as sc

id = Rhino.Display.DisplayModeDescription.ShadedId
description = Rhino.Display.DisplayModeDescription.GetDisplayMode(id)
if description:
    attributes = description.DisplayAttributes
    if attributes:
        top = System.Drawing.Color.FromArgb(0, 50, 102)
        bot = System.Drawing.Color.FromArgb(165, 165, 165)
        attributes.SetFill(top, bot)
        Rhino.Display.DisplayModeDescription.UpdateDisplayMode(description)
        sc.doc.Views.Redraw()

– Dale

1 Like

Hi @dale,

When I test in Rhino 6, it is not work well.
Message: ‘DisplayPipelineAttributes’ object has no attribute ‘SetFill’

How can I do?

Update to the latest service release of Rhino 6.

– Dale

OKay. It works well. Thanks

Hi @dale,

But in the Rhino 5.14, it has no SetFill attribute. Is there any feasible plan?

Hi @Alen_Russ,

No, there will be no further updates to Rhino 5.

– Dale