Site Tools


Enabling Orthogonal Mode

C++, .NET

Version: Rhino 4
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here

Question

How do you enable othro from the .Net SDK? I am trying to draw a line and I need ortho enabled programatically.

Answer

The state of Rhino's orthogonal drawing mode is stored in Rhino's application settings, or it's CRhinoAppSettings object. To check the current state of ortho, call CRhinoAppSettings::Ortho. To enable or disable ortho, call CRhinoAppSettings::EnableOrtho and pass in the boolean value that is appropriate. For more information on this and Rhino's application settings class, see rhinoSdkAppSettings.h. The following code illustrates how to use this feature:

C++

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoGetPoint gp;
  gp.SetCommandPrompt(L"Starting point");
  gp.GetPoint();
  if (gp.CommandResult() != success)
    return gp.CommandResult();
 
  ON_3dPoint start_point = gp.Point();
 
  CRhinoAppSettings& settings = RhinoApp().AppSettings();
  bool bOldValue = settings.Ortho();
  if (bOldValue == false)
    settings.EnableOrtho(true);
 
  gp.SetCommandPrompt(L"Ending point");
  gp.SetBasePoint(start_point);
  gp.DrawLineFromPoint(start_point, true);
  gp.GetPoint();
 
  if (bOldValue != settings.Ortho())
    settings.EnableOrtho(bOldValue);
 
  if (gp.CommandResult() != success)
    return gp.CommandResult();
 
  ON_3dPoint end_point = gp.Point();
 
  ON_Line line(start_point, end_point);
  context.m_doc.AddCurveObject(line);
  context.m_doc.Redraw();
 
  return success;
}

C#

public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
  MRhinoGetPoint gp = new MRhinoGetPoint();
  gp.SetCommandPrompt("Starting point");
  gp.GetPoint();
  if (gp.CommandResult() != IRhinoCommand.result.success)
    return gp.CommandResult();
 
  On3dPoint start_point = gp.Point();
 
  MRhinoAppSettings settings = RhUtil.RhinoApp().AppSettings();
  bool bOldValue = settings.Ortho();
  if (bOldValue == false)
    settings.EnableOrtho(true);
 
  gp.SetCommandPrompt("Ending point");
  gp.SetBasePoint(start_point);
  gp.DrawLineFromPoint(start_point, true);
  gp.GetPoint();
 
  if (bOldValue != settings.Ortho())
    settings.EnableOrtho(bOldValue);
 
  if (gp.CommandResult() != IRhinoCommand.result.success)
    return gp.CommandResult();
 
  On3dPoint end_point = gp.Point();
 
  OnLine line = new OnLine(start_point, end_point);
  context.m_doc.AddCurveObject(line);
  context.m_doc.Redraw();
 
  return IRhinoCommand.result.success;
}
developer/sdksamples/ortho.txt ยท Last modified: 2014/06/26 (external edit)