Translate area mouse coordinates to the the Node Editor's blackboard coordinates? I'm trying to to add a node from a custom made panel which pops from a pie menu. And I want the node to appear at my mouse's location (see bpy.context.active_node.location below).
The problem is that 'mouse_region_x' and 'mouse_region_y' give me the x and y mouse coordinates according to the area's size. And as its size may vary, this would give me, each time, a different offset from the cursor when the node is placed. I want my mouse's coordinates of the Node Editor area to be translated to the Node Editor's &quot;internal&quot; blackboard coordinates.
    e = get_event()

    if context.material != None:
        bpy.ops.node.add_node(
            type=&quot;ShaderNodeGroup&quot;,
            use_transform=True,
            settings=[{&quot;name&quot;:&quot;node_tree&quot;, &quot;value&quot;: &quot;bpy.data.node_groups[\&quot;%s\&quot;]&quot; % node_group_datablock_name}]
            )
        bpy.context.active_node.location = Vector((e.mouse_region_x, e.mouse_region_y)) # Need the coordinates here.

Any idea how to achieve this?
Thanks.
this'll solve it for you:
def invoke(self, context, event):
    region = context.region.view2d  
    ui_scale = context.preferences.system.ui_scale     
    x, y = region.region_to_view(event.mouse_region_x, event.mouse_region_y)
    self.x,self.y = x /ui_scale,y/ui_scale
    return self.execute(context)


Then when you want to use it:
def execute(self,context):
    new_node.location.x = self.x
    new_node.location.y = self.y

    return {'FINISHED'}