1
$\begingroup$

I use the msbug API to detect SpaceProperties.context, which, when switched to a context, triggers an Operator operation and binds the mouse event, but the mouse coordinates detected in the mouse event are always (-1, -1). How can I solve it?

the simple code is follow

import bpy

class SimpleModel(bpy.types.Operator):
    bl_idname = "object.simplemodel"
    bl_label = "simple model"
    
    def invoke(self, context, event):
        print(event.mouse_region_x)
        
    def modal(self, context, event):
        print(event.mouse_region_x)

def msgbus_callback(*args):
    current_tab = bpy.context.screen.areas[0].spaces.active.context
    gcontext = current_tab
    if(current_tab == 'VIEW_LAYER'):
        bpy.ops.object.simplemodel('INVOKE_DEFAULT')
    print(f'Current Tab: {current_tab}')

subscribe_to = bpy.types.SpaceProperties, 'context'

bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=object(),
    args=(1, 2, 3),
    notify=msgbus_callback,
)

$\endgroup$
2
  • $\begingroup$ How about providing a simplest script to reproduce the issue? $\endgroup$
    – X Y
    Commented Nov 13, 2023 at 3:33
  • $\begingroup$ I have added the code@XY $\endgroup$
    – fage
    Commented Nov 13, 2023 at 5:59

1 Answer 1

0
$\begingroup$

Oh,I get a good tip from the link poll() failed, context incorrect? - Example: bpy.ops.view3d.background_image_add()

What should I do is to override the operator execute context!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .