Okay, I got scrolling through vertex group index using mouse movement to work, the only problem is, how do I get weight painting to work during the modal operation?
Here is the solution, only need to have weight painting work while vgroup index changes
Just add 5 vertex groups and run script, search up “Start vGroup scrolling” to run operation
Press ESC key when done:
import bpy
from bpy.props import IntProperty, FloatProperty
class ModalOperator(bpy.types.Operator):
"""description"""
bl_idname = "object.modal_operator"
bl_label = "Start vGroup scrolling"
first_mouse_x = IntProperty()
first_value = FloatProperty()
def modal(self, context, event):
if event.type == 'MOUSEMOVE':
if self.lmb:
return {'PASS_THROUGH'}
ob = bpy.context.active_object
delta = self.first_mouse_x - event.mouse_x
index= delta *0.01 % 5
if event.type == 'LEFTMOUSE':
if event.value == 'PRESS':
mesh = bpy.context.object
mesh.vertex_groups.active_index = index
return {'PASS_THROUGH'}
if event.value == 'RELEASE':
return {'PASS_THROUGH'}
if event.type == 'MOUSEMOVE':
mesh = bpy.context.object
mesh.vertex_groups.active_index = index
return {'PASS_THROUGH'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
context.area.header_text_set
return {'CANCELLED'}
return {'PASS_THROUGH'}
def invoke(self, context, event):
self.lmb= False
if context.object:
self.first_mouse_x = event.mouse_x
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()
# test call
#bpy.ops.object.modal_operator('INVOKE_DEFAULT')