Help show line when mouse move event

I want to show line to location of mouse, when mouse move line to redraw. I can’t do that. Please help me.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def handle_mouse_move(object, e):
    try:
        ptS=[]
        t= e.WindowPoint.X, e.WindowPoint.Y
        ptS.append(t[0])
        ptS.append(t[1])
        ptS.append(0)
        ptS=rs.coerce3dpoint(ptS)
        print ptS
        #Show line begin 0 to location ptS
    except Exception as exp:
        print(exp)

def GetLoMouse():
    getter = Rhino.Input.Custom.GetPoint()
    getter.AcceptNothing(True)
    getter.PermitObjectSnap(False)
    getter.PermitOrthoSnap(False)
    getter.PermitConstraintOptions(False)
    getter.MouseMove += handle_mouse_move
    getter.Get(True, False)

if __name__ == '__main__':
    GetLoMouse()

Help me :frowning:

Read through this example: https://github.com/mcneel/rhino-developer-samples/blob/6/rhinopython/SampleCurveDirConduit.py

You can create a conduit just like this one, except you draw a line between the original point an the current mouse location.

2 Likes

Thank you! I’m try

Here are the methods you can call on the Display property:

https://developer.rhino3d.com/api/RhinoCommon/html/Methods_T_Rhino_Display_DisplayPipeline.htm

1 Like

This support for C# and VB. I want show them in python rhino

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def handle_mouse_move(object, e):
    try:
        sc.doc.Views.Redraw()
        ptS=[]
        t= e.WindowPoint.X, e.WindowPoint.Y
        ptS.append(t[0])
        ptS.append(t[1])
        ptS.append(0)
        ptS=rs.coerce3dpoint(ptS)
        ptSS=rs.coerce3dpoint([0,0,0])
        #Show line begin 0 to location ptS
        color = Rhino.ApplicationSettings.AppearanceSettings.TrackingColor
        Rhino.Display.DisplayPipeline.DrawDirectionArrow(ptSS,ptS,color)
    except Exception as exp:
        print(exp)

def GetLoMouse():
    getter = Rhino.Input.Custom.GetPoint()
    getter.AcceptNothing(True)
    getter.PermitObjectSnap(False)
    getter.PermitOrthoSnap(False)
    getter.PermitConstraintOptions(False)
    getter.MouseMove += handle_mouse_move
    getter.Get(True, False)

if __name__ == '__main__':
    GetLoMouse()

Error: DrawDirectionArrow() takes exactly 4 arguments (3 given)
DrawDirectionArrow need 3 arguments , why 4?

Moved this to the scripting forum-
https://discourse.mcneel.com/c/scripting

-Pascal

1 Like

You are supposed to use the Display argument from the event. That is line 30 from the conduit sample I linked:

the fourth argument is the implicit self that is given as the very first argument to the function when called as an instance method.

1 Like
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def handle_mouse_move(object,self,e):
    try:
        sc.doc.Views.Redraw()
        ptS=[]
        t= e.WindowPoint.X, e.WindowPoint.Y
        ptS.append(t[0])
        ptS.append(t[1])
        ptS.append(0)
        ptS=rs.coerce3dpoint(ptS)
        ptSS=rs.coerce3dpoint([0,0,0])
        #Show line begin 0 to location ptS
        color = Rhino.ApplicationSettings.AppearanceSettings.TrackingColor
        e.Display.DrawDirectionArrow(ptSS,ptS,color)
    except Exception as exp:
        print(exp)

def GetLoMouse():
    getter = Rhino.Input.Custom.GetPoint()
    getter.AcceptNothing(True)
    getter.PermitObjectSnap(False)
    getter.PermitOrthoSnap(False)
    getter.PermitConstraintOptions(False)
    getter.MouseMove += handle_mouse_move
    getter.Get(True, False)

if __name__ == '__main__':
    GetLoMouse()

script run but don’t draw line

That is because you don’t haven’t created a display conduit. Please revisit the sample I posted and observe the conduit class and how it is enabled and disabled.

You has use sc.doc.Views.Redraw() for show line.
I having use it but not show

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def handle_mouse_move(object,self,e):
    try:
        t= e.WindowPoint.X, e.WindowPoint.Y
        ptS.append(t[0])
        ptS.append(t[1])
        ptS.append(0)
        ptS=rs.coerce3dpoint(ptS)
        ptSS=rs.coerce3dpoint([0,0,0])
        #Show line begin 0 to location ptS
        color = Rhino.ApplicationSettings.AppearanceSettings.TrackingColor
        e.Display.DrawDirectionArrow(ptSS,ptS,color)
        sc.doc.Views.Redraw()
    except Exception as exp:
        print(exp)
def GetLoMouse():
    getter = Rhino.Input.Custom.GetPoint()
    getter.AcceptNothing(True)
    getter.PermitObjectSnap(False)
    getter.PermitOrthoSnap(False)
    getter.PermitConstraintOptions(False)
    getter.MouseMove += handle_mouse_move
    getter.Get(True, False)
if __name__ == '__main__':
    GetLoMouse()

Hi @xiix.xoox, the easiest way without setting up a full conduit is just using RhinoScript syntax to pick a point and give the method a base point. The method then does setup a dynamic display conduit on the fly to draw the line:

import Rhino
import rhinoscriptsyntax as rs

def DoSomething():
    base_pt = Rhino.Geometry.Point3d.Origin
    test_pt = rs.GetPoint("Point", base_pt)

DoSomething()

If you want to draw other objects, eg. an arrow, you can do so by using a dynamic drawn conduit. Dynamic in this context means, objects drawn in the conduit are drawn without depth buffering and are always drawn in foreground. The benefit compared to regular conduits is that the dynamic conduit does not persist after the point picker is done, so you do not have to turn it off:

import Rhino

def DoSomething():
    
    base_pt = Rhino.Geometry.Point3d.Origin
    color = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
    
    def GetPointDynamicDrawFunc(sender, args):
        line = Rhino.Geometry.Line(base_pt, args.CurrentPoint)
        args.Display.DrawArrow(line, color)
    
    gp = Rhino.Input.Custom.GetPoint()
    gp.DynamicDraw += GetPointDynamicDrawFunc
    gp.Get()
    if gp.CommandResult() == Rhino.Commands.Result.Success:
        picked_pt = gp.Point()

DoSomething()

_
c.

1 Like