McNeel Wiki
Modifying Advanced Display Settings
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
VersionRhino 4.0
SummaryDemonstrates how to modify advanced display settings using the Rhino SDK.

Overview

The new advanced display features in Rhino 4.0 give the user almost unlimited control over how objects appear on the screen. All of these features are also exposed to the SDK developer.

Rhino maintains advanced display settings using the CDisplayPipelineAttributes class. Rhino will maintain a number of these objects, one for each advanced display setting created by the user (i.e. Wireframe, Shaded, Rendered, Ghosted, X-Ray, etc.) or by 3rd party plug-ins.

The SDK developer can gain access to these objects using the Display Attributes Manager, which is implemented as a number of static fuctions found on the CRhinoDisplayAttrsMgr class.

The process for updating advanced display settings is similar to updating or modifying other objects in Rhino.

  1. Make a copy of the original.
  2. Modify one or more setting or parameters.
  3. Replace the original object with the modified copy.

C++

The following example code demonstrates how to modify advanced display settings using the Rhino SDK. In this example, a display mode's mesh wireframe thickness (in pixels) will be modified.

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    // Use the display attributes manager to build a list of display modes.
    // Note, these are copies of the originals...
    DisplayAttrsMgrList attrs_list;
    int attrs_count = CRhinoDisplayAttrsMgr::GetDisplayAttrsList( attrs_list );
    if( attrs_count == 0 )
      return failure;


    // Construct an options picker so the user can pick which
    // display mode they want modified
    CRhinoGetOption go;
    go.SetCommandPrompt( L"Display mode to modify mesh thickness" );


    ON_SimpleArray<int> opt_list( attrs_count );
    opt_list.SetCount( attrs_count );


    for( int i = 0; i < attrs_count; i++ )
    {
      // Verify the display mode had a valid 
      // CDisplayPipelineAttributes pointer
      if( 0 == attrs_list[i].m_pAttrs )
      {
        opt_list[i] = 0;
        continue;
      }


      // Get the display attributes English name
      ON_wString english_name = attrs_list[i].m_pAttrs->EnglishName();
      english_name.Remove( L'_' );
      english_name.Remove( L' ' );
      english_name.Remove( L'-' );
      english_name.Remove( L',' );
      english_name.Remove( L'.' );


      // Get the display attributes localized name
      ON_wString local_name = attrs_list[i].m_pAttrs->LocalName();
      local_name.Remove( L'_' );
      local_name.Remove( L' ' );
      local_name.Remove( L'-' );
      local_name.Remove( L',' );
      local_name.Remove( L'.' );


      // Add the command option
      opt_list[i] = go.AddCommandOption( CRhinoCommandOptionName(english_name, local_name) );
    }


    // Get the command option
    go.GetOption();
    if( go.CommandResult() != success )
      return go.CommandResult();


    const CRhinoCommandOption* opt = go.Option();
    if( 0 == opt )
      return failure;


    // Figure out which command option was picked
    int attrs_index = -1;
    for( int i = 0; i < opt_list.Count(); i++ )
    {
      if( opt_list[i] == opt->m_option_index )
      {
        attrs_index = i;
        break;
      }
    }


    // Validate...
    if( attrs_index < 0 || attrs_index >= attrs_count )
      return failure;


    // Get the display mode requested by the user
    DisplayAttrsMgrListDesc desc = attrs_list[attrs_index];
    if( 0 == desc.m_pAttrs )
      return failure;


    // Modify the desired display mode. In this case, we
    // will just set the mesh wireframe thickness to zero.
    desc.m_pAttrs->m_nMeshWireThickness = 0;


    // Use the display attributes manager to update the display mode.
    CRhinoDisplayAttrsMgr::UpdateAttributes( desc );


    // Force the document to regenerate.
    context.m_doc.Regen();


    return success;
  }

VB.NET

  Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) _
    As RMA.Rhino.IRhinoCommand.result
    'Use the display attributes manager to build a list of display modes.
    'Note, these are copies of the originals...
    Dim attrs_list As New MDisplayAttrsMgrList()
    Dim attrs_count As Integer = MRhinoDisplayAttrsMgr.GetDisplayAttrsList(attrs_list)
    If (attrs_count = 0) Then Return IRhinoCommand.result.failure


    ' Construct an options picker so the user can pick which display mode they want modified
    Dim go As New MRhinoGetOption
    go.SetCommandPrompt("Display mode to modify mesh thickness")


    Dim opt_list As New Arrayint(attrs_count)
    opt_list.SetCount(attrs_count)


    For i As Integer = 0 To attrs_count - 1
      ' Verify the display mode had a valid CDisplayPipelineAttributes pointer
      If (attrs_list(i).m_pAttrs Is Nothing) Then
        opt_list(i) = 0
        Continue For
      End If


      ' Get the display attributes English name
      Dim english_name As String = attrs_list(i).m_pAttrs.EnglishName()
      english_name = english_name.Replace("_", "")
      english_name = english_name.Replace(" ", "")
      english_name = english_name.Replace("-", "")
      english_name = english_name.Replace(",", "")
      english_name = english_name.Replace(".", "")


      ' Get the display attributes localized name
      Dim local_name As String = attrs_list(i).m_pAttrs.LocalName()
      local_name = local_name.Replace("_", "")
      local_name = local_name.Replace(" ", "")
      local_name = local_name.Replace("-", "")
      local_name = local_name.Replace(",", "")
      local_name = local_name.Replace(".", "")


      ' Add the command option
      opt_list(i) = go.AddCommandOption(New MRhinoCommandOptionName(english_name, local_name))
    Next


    ' Get the command option
    go.GetOption()
    If (go.CommandResult() <> IRhinoCommand.result.success) Then Return go.CommandResult()


    Dim opt As IRhinoCommandOption = go.Option()
    If (opt Is Nothing) Then Return IRhinoCommand.result.failure


    ' Figure out which command option was picked
    Dim attrs_index As Integer = -1
    For i As Integer = 0 To opt_list.Count() - 1
      If (opt_list(i) = opt.m_option_index) Then
        attrs_index = i
        Exit For
      End If
    Next


    ' Validate...
    If (attrs_index < 0 Or attrs_index >= attrs_count) Then
      Return IRhinoCommand.result.failure
    End If


    ' Get the display mode requested by the user
    Dim desc As MDisplayAttrsMgrListDesc = attrs_list(attrs_index)
    If (desc.m_pAttrs Is Nothing) Then Return IRhinoCommand.result.failure


    ' Modify the desired display mode. In this case, we
    ' will just set the mesh wireframe thickness to zero.
    desc.m_pAttrs.m_nMeshWireThickness = 0


    ' Use the display attributes manager to update the display mode.
    MRhinoDisplayAttrsMgr.UpdateAttributes(desc)


    ' Force the document to regenerate.
    context.m_doc.Regen()
    Return IRhinoCommand.result.success
  End Function
rename · changes · history · subscriptions · lost and found · references · file upload