Unfortunately timer apps don’t allow for certain type of context.
I already have some solutions to override other situations, but I’m struggling to adapt thoses solutions to my case.
i found answers like this one or thoses below
import bpy
from bpy.types import Menu
class VIEW3D_MT_ScriptLauncher(Menu):
bl_label = "Save Your File?"
bl_idname = "OBJECT_MT_fc_main_menulaunchscript" #other id if two pies
def draw(self, context):
layoutT = self.layout
layoutT.label(text="30 minutes passed witouth any saves", icon='COLORSET_02_VEC')
layoutT.label(text=" ")
layoutT.separator()
col = self.layout.column(align=False)
col.label(text=" Quick save ")
col.label(text=" Quick save as ")
col.label(text=" Quick save as copy ")
col.label(text=" Quick save as new version ")
col.separator()
col.label(text=" Don't ask anymore ")
col.label(text=" No ")
@staticmethod
def every_n_sec(C_dict, times=10, interval=10):
if times > 0:
bpy.ops.wm.call_menu(C_dict,
name='OBJECT_MT_fc_main_menulaunchscript')
bpy.app.timers.register(
lambda: __class__.every_n_sec(C_dict, times - 1),
first_interval=interval)
def register():
bpy.utils.register_class(VIEW3D_MT_ScriptLauncher)
def unregister():
bpy.utils.unregister_class(VIEW3D_MT_ScriptLauncher)
if __name__ == "__main__":
register()
# pass context dict to the function so bpy.ops works in timer
C_dict = bpy.context.copy()
bpy.app.timers.register(
lambda: VIEW3D_MT_ScriptLauncher.every_n_sec(C_dict))
#bpy.app.timers.register(every_n_sec, first_interval=50)
#bpy.ops.wm.call_menu(C_dict,name='OBJECT_MT_fc_main_menulaunchscript')
bpy.ops.wm.call_menu(name='OBJECT_MT_fc_main_menulaunchscript')