It is script chenge view to the opposite
import bpy
from bpy_extras import view3d_utils
from mathutils import Vector
def getView(self, context, event):
region = context.region
rv3d = context.region_data
#coord = event.mouse_region_x, event.mouse_region_y
#view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
return rv3d.view_rotation * Vector((0.0, 0.0, -1.0))
def findView(self, context, event):
vector = getView(self, context, event)
if vector == Vector((0.0, 1.0, 0.0)):
bpy.ops.view3d.viewnumpad(type='BACK', align_active=False)
elif vector == Vector((0.0, -1.0, 0.0)):
bpy.ops.view3d.viewnumpad(type='FRONT', align_active=False)
elif vector == Vector((1.0, 0.0, 0.0)):
bpy.ops.view3d.viewnumpad(type='RIGHT', align_active=False)
elif vector == Vector((-1.0, 0.0, 0.0)):
bpy.ops.view3d.viewnumpad(type='LEFT', align_active=False)
elif vector == Vector((0.0, 0.0, 1.0)):
bpy.ops.view3d.viewnumpad(type='TOP', align_active=False)
elif vector == Vector((0.0, 0.0, -1.0)):
bpy.ops.view3d.viewnumpad(type='BOTTOM', align_active=False)
class ModalOperator(bpy.types.Operator):
"""swich view to opposite"""
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
def invoke(self, context, event):
findView(self, context, event)
return {'FINISHED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
if __name__ == "__main__":
register()