Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:getpointdynamicdraw [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Dynamically Draw Geometry when Picking Points =====
 +
 +===== C# =====
 +<code c#>
 +public class GetPointDynamicDrawCommand : Command
 +{
 +  public override string EnglishName { get { return "​csGetPointDynamicDraw";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var gp = new GetPoint();
 +    gp.SetCommandPrompt("​Center point"​);​
 +    gp.Get();
 +    if (gp.CommandResult() != Result.Success)
 +      return gp.CommandResult();​
 +    var center_point = gp.Point();
 +    if (center_point == Point3d.Unset)
 +      return Result.Failure;​
 +
 +    var gcp = new GetCircleRadiusPoint(center_point);​
 +    gcp.SetCommandPrompt("​Radius"​);​
 +    gcp.ConstrainToConstructionPlane(false);​
 +    gcp.SetBasePoint(center_point,​ true);
 +    gcp.DrawLineFromPoint(center_point,​ true);
 +    gcp.Get();
 +    if (gcp.CommandResult() != Result.Success)
 +      return gcp.CommandResult();​
 +
 +    var radius = center_point.DistanceTo(gcp.Point());​
 +    var cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();​
 +    doc.Objects.AddCircle(new Circle(cplane,​ center_point,​ radius));
 +    doc.Views.Redraw();​
 +    return Result.Success;​
 +  }
 +}
 +
 +public class GetCircleRadiusPoint : GetPoint
 +{
 +  private Point3d m_center_point;​
 + 
 +  public GetCircleRadiusPoint(Point3d centerPoint)
 +  {
 +    m_center_point = centerPoint;​
 +  }
 +
 +  protected override void OnDynamicDraw(GetPointDrawEventArgs e)
 +  {
 +    base.OnDynamicDraw(e);​
 +    var cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane();​
 +    var radius = m_center_point.DistanceTo(e.CurrentPoint);​
 +    var circle = new Circle(cplane,​ m_center_point,​ radius);
 +    e.Display.DrawCircle(circle,​ System.Drawing.Color.Black);​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class GetPointDynamicDrawCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbGetPointDynamicDraw"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim gp = New GetPoint()
 +    gp.SetCommandPrompt("​Center point"​)
 +    gp.[Get]()
 +    If gp.CommandResult() <> Result.Success Then
 +      Return gp.CommandResult()
 +    End If
 +    Dim center_point = gp.Point()
 +    If center_point = Point3d.Unset Then
 +      Return Result.Failure
 +    End If
 +
 +    Dim gcp = New GetCircleRadiusPoint(center_point)
 +    gcp.SetCommandPrompt("​Radius"​)
 +    gcp.ConstrainToConstructionPlane(False)
 +    gcp.SetBasePoint(center_point,​ True)
 +    gcp.DrawLineFromPoint(center_point,​ True)
 +    gcp.[Get]()
 +    If gcp.CommandResult() <> Result.Success Then
 +      Return gcp.CommandResult()
 +    End If
 +
 +    Dim radius = center_point.DistanceTo(gcp.Point())
 +    Dim cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +    doc.Objects.AddCircle(New Circle(cplane,​ center_point,​ radius))
 +    doc.Views.Redraw()
 +    Return Result.Success
 +  End Function
 +End Class
 +
 +Public Class GetCircleRadiusPoint
 +  Inherits GetPoint
 +  Private m_center_point As Point3d
 +
 +  Public Sub New(centerPoint As Point3d)
 +    m_center_point = centerPoint
 +  End Sub
 +
 +  Protected Overrides Sub OnDynamicDraw(e As GetPointDrawEventArgs)
 +    MyBase.OnDynamicDraw(e)
 +    Dim cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +    Dim radius = m_center_point.DistanceTo(e.CurrentPoint)
 +    Dim circle = New Circle(cplane,​ m_center_point,​ radius)
 +    e.Display.DrawCircle(circle,​ System.Drawing.Color.Black)
 +  End Sub
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Geometry import *
 +from Rhino.Commands import *
 +from Rhino.Input.Custom import *
 +from scriptcontext import doc
 +from System.Drawing import *
 +
 +def RunCommand():​
 +  gp = GetPoint()
 +  gp.SetCommandPrompt("​Center point"​)
 +  gp.Get()
 +  if gp.CommandResult() <> Result.Success:​
 +    return gp.CommandResult()
 +  center_point = gp.Point()
 +  if center_point == Point3d.Unset:​
 +    return Result.Failure
 +
 +  gcp = GetCircleRadiusPoint(center_point)
 +  gcp.SetCommandPrompt("​Radius"​)
 +  gcp.ConstrainToConstructionPlane(False)
 +  gcp.SetBasePoint(center_point,​ True)
 +  gcp.DrawLineFromPoint(center_point,​ True)
 +  gcp.Get()
 +  if gcp.CommandResult() <> Result.Success:​
 +    return gcp.CommandResult()
 +
 +  radius = center_point.DistanceTo(gcp.Point())
 +  cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +  doc.Objects.AddCircle(Circle(cplane,​ center_point,​ radius))
 +  doc.Views.Redraw()
 +  return Result.Success
 +
 +class GetCircleRadiusPoint (GetPoint):
 +  def __init__(self,​ centerPoint):​
 +    self.m_center_point = centerPoint
 +  ​
 +  def OnDynamicDraw(self,​ e):
 +    cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +    radius = self.m_center_point.DistanceTo(e.CurrentPoint)
 +    circle = Circle(cplane,​ self.m_center_point,​ radius)
 +    e.Display.DrawCircle(circle,​ Color.Black)
 +
 +if __name__ == "​__main__":​
 +    RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/getpointdynamicdraw.txt ยท Last modified: 2015/09/14 (external edit)