Thanks @AndersDeleuran , I looked into these methods and while super handy (and I’m going to use them for other applications, thank you!) my goal is to retrieve the GH mouse position and mouse event for the below outlined reason:
Here’s what I’m trying to achieve as a workflow research experiment.
Have a component that listens to a GH mouse event.
Psuedo Code:
On Mouse Wire Drag (Component.Output)
Get Drag Location End
Add GH Object “Panel” with default attributes at Drag Location End
Connect Component.Output to “Panel”.Input[0]
The idea is that on any component when you drag out a wire and release the mouse in blank canvas space it will spawn a connected panel by default at the released mouse location.
So far I’m only successfully getting the cursor positions.
Code Thus Far:
import Grasshopper as gh
import System.Drawing as sd
import System.Windows.Forms as Forms
gh_GUI = gh.GUI
gh_canvas = gh.GUI.Canvas.GH_Canvas()
gh_drag = gh_GUI.GH_DragInfo
# Define variables to store data
O = []
Cp = []
Wp = []
Ds = []
De = []
# Function to run when the component is executed
def run_component(B):
global O, Cp, Wp, Ds, De
# Get the current component position in the Grasshopper canvas space
current_component_position = ghenv.Component.Attributes.Bounds.Location
# Output the current component position in the O output
O = current_component_position
# Get the cursor position from Windows
Wp = Forms.Cursor.Position
# Get The X,Y Canvas Position Of The Mouse Cursor
Cp = gh_canvas.CursorControlPosition
print(Cp)
# !!! How Can I Get The Drag Start Point And Drag End Point? !!!
Pg = gh.GUI.GH_DragInfo.Point_Drag.GetValue
Ds = gh.GUI.GH_DragInfo.Point_Start
#De = gh_drag.Point_End
return O, Cp, Wp, Ds, De
if __name__ == "__main__":
if B:
O, Cp, Wp, Ds, De = run_component(B)
# You can use the result variable to access the values returned by the function
20230823_Add_Panel_On_Wire_Drag_01b.gh (9.9 KB)
EDIT:
Just found this! (Moving in this direction now)