this addon can be useful for script that need some real time features. it can logs keyboard and mouse events, frame change during animation renders (timer event), it can change the speed of it while running (there’s a trick), it cares about instance multiplication (only one running at a time even if you try to start it again and again).
there’s also some code to use a script event logger. and a popup that appear whatever the context is (can be called from global, the console or a function for example).
bpy.ops.wm.modal_start()
bpy.ops.wm.modal_stop()
bpy.context.window_manager.modal.status = True
bpy.context.window_manager.modal.timer = True
bpy.context.window_manager.modal.timer_refresh = 0.2
bpy.context.window_manager.modal.hud = False
bpy.context.window_manager.modal.func = ‘myModalFunc(self,context,spam)’
(…)
all realtime and no crash (aha just kidding : no crashes when your script is properly connected with it )
below are some info to use it from your own scripts/addons :
the modal function to call must be available in bpy, so it should resides in a bpy class.
maybe there’s a way with global namespace but I don’t know, if so please let me know.
import blf
import time
class myPanel(bpt.types.panel) :
[...]
draw(self,context) :
[...]
row.operator('<b>wm.modal_start</b>', icon = 'GHOST_ENABLED')
row.operator('<b>wm.modal_stop</b>', icon = 'GHOST_ENABLED')
row.operator('<b>wm.modal'</b>, text = 'toggle')
class myClass(bpy.types.PropertyGroup) :
myClassValue = bpy.props.StringProperty()
# my modal function that will be called from the modal
def <b>modalAction</b>(self,self_modal,context,event) :
print(event.type)
# my hud
def <b>hud</b>(self, <b>self_modal</b>, context) :
x = self.myClassValue
if type(<b>self_modal.event</b>) != str :
# event fields are available
<b>evt = self_modal.event</b>
#if evt.type......
def myScriptInit() :
modal = bpy.context.window_manager.modal
modal.status = False
# FUNCTION CALLS
<b> modal.func = 'bpy.context.scene.myclass.modalAction(self,context,event)'
modal.hudfunc = 'bpy.context.scene.myclass.hud'</b>
modal.timer = True
modal.timer_refresh = 0.33
gvar = bpy.context.window_manager.global_var
gvar.popupreport.loglevel = 0
gvar.popupreport.loglevel = 0
def register() :
bpy.utils.register_class(myClass)
bpy.types.Scene.myclass = bpy.props.PointerProperty(type=myClass)
myScriptInit()
also you can hook a function that resides in another operator :
bpy.types.OBJECT_PT_hello.modalAction(self,context,event)
also in the addon init file you can have a look to the default_hud() and the modal_example() functions that are called by default by the addon.
hope this can help. beware the hud function call, the punishment is immediate if you write something wrong
hope this can help. i’ll publish a real example soon.
@ATOM
I used “Blend Cities” where Vector*Matrix is reversed and Vector *= Matrix replaced by Vector = Matrix * Vector …
(it just build 3 high objects out of planes … yet)
Can you post the code working without spelling errors? I am still interested to see if this version of a framechange can hold up to the task of animation for external render systems like Yafaray and so on.
watch out, you need to remove self from arguments :
so :
frameChange(self,context,event,verbose=1)
gives :
frameChange(context,event,verbose=1) in the tool
and if you hook your class to:
bpy.types.Scene.MyClass = bpy.props.PointerProperty(type=MyClass)
using context path it gives :
bpy.context.scene.MyClass
so :
bpy.context.scene.MyClass.frameChange(context, event, verbose=1)
or
bpy.context.scene.MyClass.frameChange(context, event)
works.
and if not… please let me know… maybe I mismatch release version… (mine is 0.2)
watch out, you need to remove self from arguments :
so :
frameChange(self,context,event,verbose=1)
gives :
frameChange(context,event,verbose=1) in the tool
…
or you need to
class MyClass(bpy.types.PropertyGroup):
def frameChange(self,selfmodal,context,event,verbose=1):
[…]
and type :
bpy.context.scene.MyClass.frameChange(self,selfmodal,context, event)
in the tool or in bpy.context.window_manager.modal.func
it’s a bit tricky… I’ll try to make it more simple in next version. also I replaced “your function is buggy” by “wrong path or buggy function.”…