1

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, )

fage
  • 109
  • 7

1 Answers1

0

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!

fage
  • 109
  • 7