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?
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:
The following sample code demonstrates how to change the unit's display precision of the current document using the Rhino SDK.
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;
}
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;
}
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