Hi, guys, I`m trying to write a python script to create a point that follows the mouse moving and then stays at the position where the mouse is clicked.
I tried rs.addpoint() but it only create point after mouse clicked. Is there other ways to make it?
Im quit new on this aspect, for me, it means a lot tricky Im afraid…
when you mentioned “event handling” & “display conduits”, do you means they are 2 different solutions for my need or they must cooperate together to work? The official introduction is not so detailed, do you know any completed tutorial on this aspect?
I downloaded it, but it is not able to work anyway. And I read its code, it gets mouse position from screen while my intention is to get mouse position in 3D space dynamically in realtime.
Edit: Just read your original question, you probably want to have a look at the Rhino.UI.MouseCallback class to intercept mouse movement and clicks (i.e. in addition to its position in 2D/3D).
Thank you for the quick fix, Anders. Now it’s working.
I’ll spend some time to dive in, to see what I can learn from it. I’m pretty sure it`s a very valuable reference in my case.
In case that helps, here is a simple example using RhinoScript, should be easy to port to Python.
This works assuming you are ok with a loop and not getting into complexities of events programming:
Option Explicit
Call PointOnMouse()
Sub PointOnMouse()
Dim c,p
c = Rhino.GetCursorPos()(0)
p = Rhino.AddPoint(c)
Do
Rhino.Sleep 10
c = Rhino.GetCursorPos()(0)
Call Rhino.PointCoordinates(p, c)
If KeyStatus(&h01) Then Exit Sub
Loop
End Sub
Function KeyStatus(hexKey)
Call Rhino.GetAsyncKeyState(hexKey)
If Cbool(Rhino.GetAsyncKeyState(hexKey) And -32768) Then KeyStatus = True Else KeyStatus = False
End Function
Thanks, Jarek. I’ll look into this script as well.
I did some research on Official examples and found out that there is an example of dynamic drawing circle code that might be useful for my goal. Dynamically Draw Geometry when Picking Points
I think if I can replace drawcircle to addpoint/drawpoint, it may work.
But in this code, I’m confused about the line with “e.Display.DrawCircle(circle, Color.Black)”. What is the “e” mean in this situation? I didn’t find its explaination on this page: Rhinocommon API