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

This is a way to achieve it (don’t forget to add a mousein1 and to set it to absolute)(don’t forget also create a movifilein1 top. Set the offset_px_x and
offset_px_y if needed !!!IMPORTANT IF TOUCHDESIGNER WINDOW CHANGE IT WILL AFFECT THE OFFSET"

def onFrameStart(frame):
    # === OFFSET personnalisable (en pixels, appliqué avant zoom) ===
    offset_px_x = -800  # décalage horizontal
    offset_px_y = -300  # décalage vertical

    # === Références ===
    mouse = op('mousein1')
    pane = ui.panes['pane1']
    panel = pane.owner
    annotate = op('moviefilein1')

    # === Calcul position corrigée selon zoom et scroll ===
    zoom = pane.zoom
    origin_x = pane.x
    origin_y = pane.y
    mouse_x = mouse['tx']
    mouse_y = mouse['ty']
    panel_width = panel.width
    panel_height = panel.height

    # Position en unités réseau
    mx = (mouse_x + offset_px_x - panel_width / 2) / zoom + origin_x
    my = (mouse_y + offset_px_y - panel_height / 2) / zoom + origin_y

    # === Mise à jour de la position de annotate1 ===
    annotate.nodeX = mx
    annotate.nodeY = my


thank you for this

1 Like