How to get the coordinates of the mouse position relative to the node network grid

Hi,

I want to get mouse position in network editor, such operator position. I use ui.pans[0].x/y and miuse in(Absolut) to caculate, But the numerical mapping is wrong.

Is there any way to achieve it? Thanks

1 Like

I have no idea if this is possible in the 1 step elegant way you are hoping for - would be sweet! However, you might be able to in a very annoying round about way, calculate the position in graph space by transforming your absolute mouse coordinates from the raw coordinates into the desired coordinate space.

For instance, something like this:

  1. absolute windows desktop x/y
  2. x/y coords relative to entire TD window
  3. x/y coords relative to a specific TD pane
  4. x/y coords relative to the zoom/offset of a network pane’s graph.

1 is easy, already have that. 2 is possible, though not simple. can use python ctypes library to access windows and their positions, etc. 3 is maybe not possible, though you can maybe assume certain fixed offsets from the TD window if your environment is pretty controlled. 4 is possible.

@lucasm’s solution just might work but is certainly a huge pain.

What are you trying to achieve… maybe there is a more straightforward way.

1 Like

Thanks!!!
I used the fourth method to remap the mouse position before, but when I zoom the grid, I have to click the mouse and drag again to refresh the data.
01

1 Like

hey @Zink would you mind sharing your solution? can’t wrap my brain around this one. just the python or the equation would be fine - don’t need a tox (unless you’d prefer to share that).

hi,
Could you explain how you managed to do it please?

Best regard,
Nelson

Hi =) i manage to do it finally =0 you can try this (don’t forget to add a mousein1 and to set it to absolute)

def onFrameStart(frame):
# Access the desired pane and network
p = ui.panes[‘pane1’] # Adjust pane name or use index as needed
n = op(‘/project1’) # Target network editor operator

# Retrieve current zoom and origin
current_zoom = p.zoom
origin_x = p.x
origin_y = p.y

# Access mousein1 operator
mouse = op('mousein1')  # Replace with actual operator name if different

# Get the absolute mouse position from mousein1 CHOP channels
mouse_x = mouse['tx']  # 'tx' is the channel name for x position
mouse_y = mouse['ty']  # 'ty' is the channel name for y position

# Adjust mouse coordinates based on zoom and origin
mapped_x = (mouse_x - 1100) / current_zoom + origin_x
mapped_y = (mouse_y - 600) / current_zoom + origin_y

# Move the moviefilein1 operator
movie_op = op('moviefilein1')  # Replace with the exact name of the operator
movie_op.nodeX = mapped_x
movie_op.nodeY = mapped_y

# Print the mapped coordinates for debugging
print(f"Mapped Mouse Coordinates: ({mapped_x:.2f}, {mapped_y:.2f})")

return

thank you for this