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()
nathanletwory
(Nathan 'jesterKing' Letwory)
November 2, 2018, 10:56am
3
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
nathanletwory
(Nathan 'jesterKing' Letwory)
November 2, 2018, 11:08am
5
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?
pascal
(Pascal Golay)
November 2, 2018, 5:56pm
8
Moved this to the scripting forum-
https://discourse.mcneel.com/c/scripting
-Pascal
1 Like
nathanletwory
(Nathan 'jesterKing' Letwory)
November 2, 2018, 8:29pm
9
You are supposed to use the Display argument from the event. That is line 30 from the conduit sample I linked:
# DrawOverlay override
def DrawOverlay(self, e):
if self.m_curve:
color = Rhino.ApplicationSettings.AppearanceSettings.TrackingColor
for x in range(0, self.m_arrow_count):
d = x / (self.m_arrow_count - 1)
t = self.m_curve.Domain.ParameterAt(d)
pt = self.m_curve.PointAt(t)
dir = self.m_curve.TangentAt(t)
e.Display.DrawDirectionArrow(pt, dir, color)
@property
def Curve(self):
return self.m_curve
@Curve.setter
def Curve(self, val):
self.m_curve = val
################################################################################
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
xiix.xoox
(Azure)
November 3, 2018, 2:30am
10
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
nathanletwory
(Nathan 'jesterKing' Letwory)
November 3, 2018, 6:54am
11
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.
xiix.xoox
(Azure)
November 3, 2018, 7:12am
12
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()
clement
November 4, 2018, 3:44pm
13
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