[Houdini][Python] Move the node based on the mouse/cursor position?

Hi,

Is there a way I can move a specific node based on the mouse/cursor’s positions?

I tried the setPosition or the move method but it doesn’t work. It also doesn’t error out.

Here’s my code so far:


new_node = con.createNode(node_name)
pos = QtGui.QCursor.pos()
new_pos = hou.Vector2(values=(pox.x(), pox.x()))
new_node.setPosition(new_pos)
new_node.move(new_pos)

May I ask what am I missing?

I have gotten the mouse position in a network pane using this code.

node.setPosition(
    hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor).cursorPosition()
)

Which i use in this function

def create_merge_node_at_mouse(**kwargs):
    """
    Create a merge node at your mouse position with whatever node is currently selected
    :param kwargs:
    :return:
    """
    try:
        (node,) = hou.selectedNodes()
        node.setColor(hou.Color(0.302, 0.525, 0.114))
        parent = node.parent()
        merge = parent.createNode('object_merge', '%s_MERGE' % node.name().upper())
        merge.setPosition(
            hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor).cursorPosition()
        )
        merge.parm('objpath1').set(merge.relativePathTo(node))
        merge.setColor(hou.Color(0.475, 0.812, 0.204))
    except Exception as e:
        pass
1 Like

Hi @csprance

Thanks for the response. Works as expected :slight_smile: