import bpy, bmesh
from bpy.props import IntProperty, FloatProperty
class ModalOperator(bpy.types.Operator):
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
def modal(self, context, event):
object = bpy.context.object
mesh = object.data
bm = bmesh.from_mesh(mesh)
if event.type == 'MOUSEMOVE':
bm.verts[0].co.x += 0.1
context.area.tag_redraw() # The trick
elif event.type == 'LEFTMOUSE':
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
print("Invoke")
if context.object:
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
if __name__ == "__main__":
register()
The answer:
The issue is that python doesn’t have notifier access yet, so you cant
easily tell all 3D views to redraw from the console.
(though it wouldnt be hard to write a python function to do so.)
if you run a tool from the 3D view you can redraw the active view.
context.area.tag_redraw()
If you have a modifier applied, rna can refresh this via the object.
obj.update_tag(refresh={‘DATA’})
There are still some TODO’s - how to tell the editmeshes ngons to be
re-tesselated, how to sync between the bmesh and the original mesh and
updating as you noticed.