Switch shading mode while navigating the 3D View
import bpy
class VIEW3D_OT_View_box_orbit(bpy.types.Operator):
"""Switch shading mode while navigating the 3D View"""
bl_idname = "view3d.navigate_shade_switch"
bl_label = "Navigating Toggled Shading"
nav_mode = bpy.props.EnumProperty(name = "Navigation", items=[
("rotate", "Rotate", "Rotate the view"),
("move", "Move", "Move the view"),
("zoom", "Zoom", "Zoom in/out in the view"),
("dolly", "Dolly", "Dolly in/out in the view"),
("fly", "Fly", "Interactively fly around the scene"),
])
shade_mode = bpy.props.EnumProperty(name = "Shading", items=[
("BOUNDBOX", "Bounding Box", "Display the object's local bounding boxes only", "BBOX", 1),
("WIREFRAME", "Wireframe", "Display the object as wire edges", "WIRE", 2),
("SOLID", "Solid", "Display the object solid, lit with default OpenGL lights", "SOLID", 3),
("TEXTURED", "Textured", "Display the object solid, with a texture", "POTATO", 4),
("MATERIAL", "Material", "Display objects solid, with GLSL material", "MATERIAL", 5),
("RENDERED", "Rendered", "Display render preview", "SMOOTH", 6),
])
def modal(self, context, event):
if not hasattr(self, "navigating"):
self.navigating = True
getattr(bpy.ops.view3d, self.nav_mode)("INVOKE_DEFAULT")
return {"RUNNING_MODAL"}
elif event.type == "TIMER":
return {"RUNNING_MODAL"}
context.space_data.viewport_shade = self.shading
return {"FINISHED"}
def invoke(self, context, event):
v3d = context.space_data
if v3d.type == "VIEW_3D":
self.shading = v3d.viewport_shade
try:
v3d.viewport_shade = self.shade_mode
except TypeError:
pass # Shading mode not supported.
context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"}
return {"CANCELLED"}
bpy.utils.register_class(VIEW3D_OT_View_box_orbit)