Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:mousecallback [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: handle mouse events =====
 +
 +===== C# =====
 +<code c#>
 +public class MyMouseCallback : MouseCallback
 +{
 +  protected override void OnMouseDown(MouseCallbackEventArgs e)
 +  {
 +    base.OnMouseDown(e);​
 +    RhinoApp.WriteLine("​active viewport: {0}", e.View.ActiveViewport.Name);​
 +  }
 +}
 +
 +public class MouseCallbackCommand : Command
 +{
 +  private MouseCallback m_mc;
 +
 +  public override string EnglishName { get { return "​csMouseCallbackCommand";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    if (m_mc == null)
 +    {
 +      m_mc = new MyMouseCallback();​
 +      m_mc.Enabled = true;
 +    }
 +    RhinoApp.WriteLine("​Click somewhere in a vieport ...");
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class MyMouseCallback
 +  Inherits MouseCallback
 +  Protected Overrides Sub OnMouseDown(e As MouseCallbackEventArgs)
 +    MyBase.OnMouseDown(e)
 +    RhinoApp.WriteLine("​active viewport: {0}", e.View.ActiveViewport.Name)
 +  End Sub
 +End Class
 +
 +Public Class MouseCallbackCommand
 +  Inherits Command
 +  Private m_mc As MouseCallback
 +
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbMouseCallbackCommand"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    If m_mc Is Nothing Then
 +      m_mc = New MyMouseCallback()
 +      m_mc.Enabled = True
 +    End If
 +    RhinoApp.WriteLine("​Click somewhere in a vieport ...")
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.UI import *
 +
 +class MyMouseCallback(MouseCallback):​
 +  def OnMouseDown(self,​ e):
 +    print "​active viewport: {0}"​.format(e.View.ActiveViewport.Name)
 +
 +def RunCommand():​
 +  m_mc = MyMouseCallback()
 +  m_mc.Enabled = True
 +
 +  RhinoApp.WriteLine("​Click somewhere in a vieport ...")
 +  return Result.Success
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/mousecallback.txt ยท Last modified: 2015/09/14 (external edit)