0
$\begingroup$

Trying to port an AddMIDI addone to B2.8 and started getting this error followed with blender crash

TypeError: WindowManager.event_timer_add(): required parameter "window" to be a keyword argument!
location: C:\Portable\blender\2.80\scripts\modules\bpy\ops.py:200
location: <unknown location>:-1
location: <unknown location>:-1
Error   : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF79168062A
Module  : C:\Portable\blender\blender.exe`

Here is a minimal version replicating error. This script works well in B2.79. Not sure if I am doing something wrong or it is the B2.8 bug. API documentation doesn't seem to have this method changed for B2.8. Is there any way to get it working on the latest beta version?

import bpy
from bpy.utils import register_class, unregister_class
import time

class ModalTimer(bpy.types.Operator):
    bl_idname = "addmidi.modal_timer_operator"
    bl_label = "timer"

    _timer = None 

    def modal(self, context, event):
        if event.type == 'TIMER':
            print('looping')
        return {'PASS_THROUGH'}            

    def execute(self, context):
        context.window_manager.modal_handler_add(self)
        self._timer = context.window_manager.event_timer_add(1/100, context.window)
        return {'RUNNING_MODAL'}

class Paneladd(bpy.types.Panel):
    bl_label = "panel"
    bl_category = "category"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

    def draw(self, context):
        layout = self.layout
        col = layout.column(align=True)
        row = col.row(align=True)
        row.operator("addmidi.start", text='start loop')

class Button(bpy.types.Operator):
    bl_idname = "addmidi.start"
    bl_label = "start"

    def execute(self, context):
        bpy.ops.addmidi.modal_timer_operator()
        return{'FINISHED'}

def register():
    bpy.utils.register_class(ModalTimer)
    bpy.utils.register_class(Paneladd)
    bpy.utils.register_class(Button)

def unregister():
    bpy.utils.unregister_class(ModalTimer)
    bpy.utils.unregister_class(Paneladd)
    bpy.utils.unregister_class(Button)

if __name__ == "__main__": 
    register()
$\endgroup$
0
$\begingroup$

All optional arguments now require keywords in 2.80.

event_timer_add(1/100, context.window)

becomes

event_timer_add(1/100, window=context.window)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.