Hey guys I made an addon that is a modal operator, all it does is add a solidify modifier and then alters the
thickness when shift is held down and the mouse is moved.
I have worked on it for 2 days and admit defeat, I don’t know how to make it remember what the thickness is at
if shift is not pressed.
To clarify I want to add thickness when shift is held, and continue to add thickness when shift is held again.
at the moment it is resetting each time i release and press shift.
Please help
bl_info = {
"name": "test",
"author": "",
"version": (1, 0),
"blender": (2, 78, 0),
"description": "Test",
"category": "3D View"}
import bpy
class ModalOperator(bpy.types.Operator):
bl_idname = "test.test"
bl_label = "Simple Modal Operator"
def modal(self, context, event):
if event.type == 'MOUSEMOVE':
if event.shift:
delta = self.first_mouse_x - event.mouse_x
for mod in bpy.context.scene.objects.active.modifiers:
if mod.type == "SOLIDIFY":
bpy.context.object.modifiers[mod.name].thickness = self.first_value + delta * 0.01
elif event.type == 'LEFTMOUSE':
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
bpy.ops.object.modifier_remove(modifier="Solidify")
context.object.location.x = self.first_value
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
self.first_mouse_x = event.mouse_x
self.first_value = context.object.location.x
bpy.ops.object.modifier_add(type='SOLIDIFY')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
pass
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)