Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:getangle [2015/09/14]
developer:rhinocommonsamples:getangle [2020/08/14] (current)
Line 1: Line 1:
 +===== Sample: Interactively Pick an Angle =====
 +
 +===== C# =====
 +<code c#>
 +public class GetAngleCommand : Command
 +{
 +  public override string EnglishName { get { return "csGetAngle"; } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var gp = new GetPoint();
 +    gp.SetCommandPrompt("Base point");
 +    gp.Get();
 +    if (gp.CommandResult() != Result.Success)
 +      return gp.CommandResult();
 +    var base_point = gp.Point();
 +
 +    gp.SetCommandPrompt("First reference point");
 +    gp.DrawLineFromPoint(base_point, true);
 +    gp.Get();
 +    if (gp.CommandResult() != Result.Success)
 +      return gp.CommandResult();
 +    var first_point = gp.Point();
 +
 +    double angle_radians;
 +    var rc = RhinoGet.GetAngle(
 +      "Second reference point", base_point, first_point, 0, out angle_radians);
 +    if (rc == Result.Success)
 +      RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians));
 +
 +    return rc;
 +  }
 +}
 +</code>
 +===== VB.NET =====
 +<code vb>
 +Public Class GetAngleCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "vbGetAngle"
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim gp = New GetPoint()
 +    gp.SetCommandPrompt("Base point")
 +    gp.[Get]()
 +    If gp.CommandResult() <> Result.Success Then
 +      Return gp.CommandResult()
 +    End If
 +    Dim base_point = gp.Point()
 +
 +    gp.SetCommandPrompt("First reference point")
 +    gp.DrawLineFromPoint(base_point, True)
 +    gp.[Get]()
 +    If gp.CommandResult() <> Result.Success Then
 +      Return gp.CommandResult()
 +    End If
 +    Dim first_point = gp.Point()
 +
 +    Dim angle_radians As Double
 +    Dim rc = RhinoGet.GetAngle(
 +      "Second reference point", base_point, first_point, 0, angle_radians)
 +    If rc = Result.Success Then
 +      RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians))
 +    End If
 +    Return rc
 +  End Function
 +End Class
 +d Namespace
 +</code>
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.Input import *
 +from Rhino.Input.Custom import *
 +
 +def RunCommand():
 +  gp = GetPoint()
 +  gp.SetCommandPrompt("Base point")
 +  gp.Get()
 +  if gp.CommandResult() <> Result.Success:
 +    return gp.CommandResult()
 +  base_point = gp.Point()
 +
 +  gp.SetCommandPrompt("First reference point")
 +  gp.DrawLineFromPoint(base_point, True)
 +  gp.Get()
 +  if gp.CommandResult() <> Result.Success:
 +    return gp.CommandResult()
 +  first_point = gp.Point()
 +
 +  
 +  rc, angle_radians = RhinoGet.GetAngle(
 +    "Second reference point", base_point, first_point, 0)
 +  if rc == Result.Success:
 +    print "Angle = {0} degrees".format(RhinoMath.ToDegrees(angle_radians))
 +  return rc
 +
 +if __name__ == "__main__":
 +  RunCommand()
 +</code>
 +
 +{{tag>Developer rhinocommon}}