McNeel Wiki
How To: Interactively Pick an Angle
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

日本語

한국어

中文(繁體)

 
.
DeveloperC++, .NET
SummaryDemonstrates how to use the CRhinoGetAngle class to pick an angle.

The following sample code demonstrates how to prompt the user to define an angle by using the SDK's CRhinoGetAngle class. In this example, angle selection will be constrained to the active construction plane. Also, the user will be prompted to pick both the base point and the first reference point, line Rhino's Rotate command.

C++

  CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  {
    // Prompt for base point
    CRhinoGetPoint gp;
    gp.SetCommandPrompt( L"Base point" );
    gp.ConstrainToConstructionPlane( FALSE );
    gp.GetPoint();
    if( gp.CommandResult() != CRhinoCommand::success )
      return gp.CommandResult();


    // Get first picked point
    ON_3dPoint origin = gp.Point();


    // Get view used during GetPoint
    CRhinoView* view = gp.View();
    if( !view )
    {
      // If scripted, get active view
      view = ::RhinoApp().ActiveView();
      if( !view )
        return CRhinoCommand::failure;
    }


    // Get view's construction plane and move it to the picked point
    ON_Plane plane = view->Viewport().ConstructionPlane().m_plane;
    plane.SetOrigin( origin );


    // Prompt for first reference point
    gp.SetCommandPrompt( L"First reference point" );
    gp.SetBasePoint( origin );
    gp.DrawLineFromPoint( origin, TRUE );
    gp.Constrain( plane );  // Constrain picking to plane
    gp.GetPoint();
    if( gp.CommandResult() != CRhinoCommand::success )
      return gp.CommandResult();


    // Get second picked point
    ON_3dPoint refpt = gp.Point();


    // Prompt for angle
    CRhinoGetAngle ga;
    ga.SetCommandPrompt( L"Second reference point" );
    ga.SetBasePoint( origin );
    ga.SetBase( origin );
    ga.SetReferencePoint( refpt );
    ga.Constrain( plane );  // Constrain picking to plane
    ga.GetAngle();
    if( ga.CommandResult() != CRhinoCommand::success )
      return ga.CommandResult();


    // Results
    double radians = ga.Angle();
    double degrees = radians * (180.0/ON_PI);
    RhinoApp().Print( L"Angle = %f.\n", degrees );


    return CRhinoCommand::success;
  }

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
    As RMA.Rhino.IRhinoCommand.result


    ' Prompt for base point
    Dim gp As New MRhinoGetPoint()
    gp.SetCommandPrompt("Base point")
    gp.ConstrainToConstructionPlane(False)
    gp.GetPoint()
    If (gp.CommandResult() <> IRhinoCommand.result.success) Then Return gp.CommandResult()


    ' Get first picked point
    Dim origin As On3dPoint = gp.Point()


    ' Get view used during GetPoint
    Dim view As MRhinoView = gp.View()
    If (view Is Nothing) Then
      ' If scripted, get active view
      view = RhUtil.RhinoApp.ActiveView
      If (view Is Nothing) Then Return IRhinoCommand.result.failure
    End If


    ' Get view's construction plane and move it to the picked point
    Dim plane As New OnPlane(view.ActiveViewport().ConstructionPlane().m_plane)
    plane.SetOrigin(origin)


    ' Prompt for first reference point
    gp.SetCommandPrompt("First reference point")
    gp.SetBasePoint(origin)
    gp.DrawLineFromPoint(origin, True)
    gp.Constrain(plane) ' Constrain picking to plane
    gp.GetPoint()
    If (gp.CommandResult() <> IRhinoCommand.result.success) Then Return gp.CommandResult()


    ' Get second picked point
    Dim refpt As On3dPoint = gp.Point()


    ' Prompt for angle
    Dim ga As New mrhinogetangle()
    ga.SetCommandPrompt("Second reference point")
    ga.SetBasePoint(origin)
    ga.SetBase(origin)
    ga.SetReferencePoint(refpt)
    ga.Constrain(plane)  ' Constrain picking to plane
    ga.GetAngle()
    If (ga.CommandResult() <> IRhinoCommand.result.success) Then Return ga.CommandResult()


    ' Results
    Dim radians As Double = ga.Angle()
    Dim degrees As Double = radians * 180.0 / OnUtil.On_PI
    RhUtil.RhinoApp.Print("Angle = " + degrees.ToString() + vbCrLf)


    Return IRhinoCommand.result.success
  End Function

C# (Rhino 4)

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    // Prompt for base point
    MRhinoGetPoint gp = new MRhinoGetPoint();
    gp.SetCommandPrompt("Base point");
    gp.ConstrainToConstructionPlane(false);
    gp.GetPoint();
    if(gp.CommandResult() != IRhinoCommand.result.success)
      return gp.CommandResult();


    // Get first picked point
    On3dPoint origin = gp.Point();
    // Get view used during GetPoint
    MRhinoView view = gp.View();
    if(view == null)
    {
      // If scripted, get active view
      view = RhUtil.RhinoApp().ActiveView();
      if(view == null)
        return IRhinoCommand.result.failure;
    }


    // Get view's construction plane and move it to the picked point
    OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);
    plane.SetOrigin(origin);


    // Prompt for first reference point
    gp.SetCommandPrompt("First reference point");
    gp.SetBasePoint(origin);
    gp.DrawLineFromPoint(origin, true);
    gp.Constrain(plane); // Constrain picking to plane
    gp.GetPoint();
    if(gp.CommandResult() != IRhinoCommand.result.success)
      return gp.CommandResult();


    // Get second picked point
    On3dPoint refpt = gp.Point();


    // Prompt for angle
    MRhinoGetAngle ga = new MRhinoGetAngle();
    ga.SetCommandPrompt("Second reference point");
    ga.SetBasePoint(origin);
    ga.SetBase(origin);
    ga.SetReferencePoint(refpt);
    ga.Constrain(plane); // Constrain picking to plane
    ga.GetAngle();
    if(ga.CommandResult() != IRhinoCommand.result.success)
      return ga.CommandResult();


    // Results
    double radians = ga.Angle();
    double degrees = radians * 180.0 / OnUtil.On_PI;
    RhUtil.RhinoApp().Print("Angle = " + degrees.ToString() + "\n");
    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload