hi again, this is the 3 bpy threads/days guy talking.
I’m writing an addon where I need a frame_change like modal operator. I’d like the modal to start at ‘addon enable’ time.
when I enable the addon in userprefs, frame_change is started but will only execute when focus is on the userprefs window not on the blender window, which is quite useless
it works fine when I load the script in a block text, I guess this is context related but I found no info or examples anywhere about it. (like for the update option in the bpy.props.XxxxProperties btw )
I tried this in the invoke/execute modal functions :
bpy.data.window_managers['WinMan'].modal_handler_add(self)
but useless. the documentation lacks info about self and context usage I think… please share gurus
also I call some operators to initialise my addon from the init register() function… not sure if it’s the right way do do it.
… and all the addon resides in the init file, no modules apart.
below is a silly code with an framechange operator that only work in the user preferences window.
copy/paste in 2.58/scripts/addons then enable it in user pref Add-ons > Animation
…but this will work as it should if you copy/paste it directly in a block text
thanks for any pointers or explanations about this and/or context usage.
bl_info = {
"name": "frame change watchdog",
"description": "dummy add-on",
"author": "Jerome Mahieux (littleneo)",
"version": (0, 1),
"blender": (2, 5, 7),
"api": 36339,
"location": "earth",
"warning": "it's dummy",
"wiki_url": "",
"tracker_url": "",
"category": "Animation"}
import bpy
class frameChanged(bpy.types.Operator):
'''Implement a frame change event.'''
bl_idname = "object.frame_change"
bl_label = "Frame Change Event"
last_frame = bpy.props.IntProperty()
def __init__(self):
print("--> frameChanged ACTIVATED")
def __del__(self):
print("--> frameChanged DEACTIVATED")
def modal(self, context, event):
if event.type in ('ESC'):
return {'CANCELLED'}
if self.properties.last_frame != bpy.context.scene.frame_current :
print (" frameChanged To:" + str(bpy.context.scene.frame_current))
self.properties.last_frame = bpy.context.scene.frame_current
return {'PASS_THROUGH'}
def invoke(self, context, event):
print ("invoke")
context.window_manager.modal_handler_add(self)
#bpy.data.window_managers['WinMan'].modal_handler_add(self)
#self.execute(context)
return {'RUNNING_MODAL'}
def execute(self, context):
context.window_manager.modal_handler_add(self)
#bpy.data.window_managers['WinMan'].modal_handler_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(frameChanged)
bpy.ops.object.frame_change()
def unregister():
bpy.utils.unregister_class(frameChanged)
if __name__ == "__main__":
register()