Skip to content

Instantly share code, notes, and snippets.

@carter2422
Created January 29, 2014 21:38
Show Gist options
  • Save carter2422/8697755 to your computer and use it in GitHub Desktop.
Save carter2422/8697755 to your computer and use it in GitHub Desktop.
Quick Modifiers Modal
import bpy
from bpy.props import IntProperty, FloatProperty
class ModalOperator(bpy.types.Operator):
"""Move an object with the mouse, example"""
bl_idname = "object.modal_operator"
bl_label = "Simple Mirror"
first_mouse_x = IntProperty()
first_value = FloatProperty()
mesh = bpy.context.active_object
def modal(self, context, event):
if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
obj = bpy.context.active_object
print(obj)
return {'PASS_THROUGH'}
elif event.type == 'SPACE':
bpy.context.scene.objects.active = self.mesh
bpy.ops.object.modifier_add(type='MIRROR')
self.mesh.select = True
return {'FINISHED'}
elif event.type in {'RIGHTMOUSE', 'ESC'}:
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
context.window_manager.modal_handler_add(self)
self.header_message = "Select an object"
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment