Sdk Display Precision
Last changed: -204.177.179.116

.
DeveloperC++, .NET
SummaryDemonstrates how to change the unit's display precision of the current document using the Rhino SDK.

Question

How can I modify a document's display precision, the "display precision" option found in the Units page in the Options dialog, using the Rhino SDK?

Answer

A document's display precision, the number of decimal places used for the distance display, is maintained on an ON_3dmUnitsAndTolerances object, which in turn is stored on a CRhinoDocProperties object which is a memmber of the current CRhinoDoc object. To modify this variable, you will need to:

  1. Make a copy of the document's ON_3dmUnitsAndTolerances object.
  2. Modify the object's m_distance_display_precision member variable.
  3. Replace the current ON_3dmUnitsAndTolerances with the newly modified one.

Example

The following sample code demonstrates how to change the unit's display precision of the current document using the Rhino SDK.

C++

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    // Make a copy of the current model units and tolerances
    ON_3dmUnitsAndTolerances units = context.m_doc.Properties().ModelUnitsAndTolerances();


    // Prompt the user to enter a new display precision value
    CRhinoGetInteger gi;
    gi.SetCommandPrompt( L"New display precision" );
    gi.SetDefaultInteger( units.m_distance_display_precision );
    gi.SetLowerLimit( 0 );
    gi.SetUpperLimit( 6 );
    gi.GetInteger();
    if( gi.CommandResult() == CRhinoCommand::success )
    {
      // The the user's input
      int distance_display_precision = gi.Number();
      if( distance_display_precision != units.m_distance_display_precision )
      {
        units.m_distance_display_precision = distance_display_precision;
        // Replace the current setting with our updated value
        context.m_doc.Properties().SetModelUnitsAndTolerances( units, false );
      }
    }


    return CRhinoCommand::success;
  }

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    // Make a copy of the current model units and tolerances
    On3dmUnitsAndTolerances units =
       new On3dmUnitsAndTolerances(context.m_doc.Properties().ModelUnitsAndTolerances());


    // Prompt the user to enter a new display precision value
    MRhinoGetInteger gi = new MRhinoGetInteger();
    gi.SetCommandPrompt( "New display precision" );
    gi.SetDefaultInteger( units.m_distance_display_precision );
    gi.SetLowerLimit( 0 );
    gi.SetUpperLimit( 6 );
    gi.GetInteger();
    if( gi.CommandResult() == IRhinoCommand.result.success )
    {
      // The the user's input
      int distance_display_precision = gi.Number();
      if( distance_display_precision != units.m_distance_display_precision )
      {
        units.m_distance_display_precision = distance_display_precision;
        // Replace the current setting with our updated value
        context.m_doc.Properties().SetModelUnitsAndTolerances( units, false );
      }
    }
    return IRhinoCommand.result.success;
  }

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) _
    As RMA.Rhino.IRhinoCommand.result
    ' Make a copy of the current model units and tolerances
    Dim units As New On3dmUnitsAndTolerances(context.m_doc.Properties().ModelUnitsAndTolerances())


    ' Prompt the user to enter a new display precision value
    Dim gi As New MRhinoGetInteger()
    gi.SetCommandPrompt("New display precision")
    gi.SetDefaultInteger(units.m_distance_display_precision)
    gi.SetLowerLimit(0)
    gi.SetUpperLimit(6)
    gi.GetInteger()
    If (gi.CommandResult() = IRhinoCommand.result.success) Then
      ' The the user's input
      Dim distance_display_precision As Integer = gi.Number()
      If (distance_display_precision <> units.m_distance_display_precision) Then
        units.m_distance_display_precision = distance_display_precision
        ' Replace the current setting with our updated value
        context.m_doc.Properties().SetModelUnitsAndTolerances(units, False)
      End If
    End If
    Return IRhinoCommand.result.success
  End Function