Created
January 29, 2014 21:38
-
-
Save carter2422/8697755 to your computer and use it in GitHub Desktop.
Quick Modifiers Modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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