# Activate Smooth Shading and Subsurf Level with One Shortcut in Both Object and Edit Mode

Maybe I'm missing something, but I feel like changing the subsurf level and shading needs a lot of keypresses.
Usually, I model in edit mode with subsurf off and flat shading. Sometimes, however, I would like to see (for a moment), how the object would look with smooth shading and subsurf active.

To do this, I have to Ctrl+Tab out from edit mode to object mode, press Ctrl+1 (or 2), right-click on the object, and change to smooth shading.

I believe that it would make sense if when you increase the subsurf level beyond zero (Ctrl+1, Ctrl+2 etc.), the selected mesh would also change shading from flat to smooth. Likewise, pressing Ctrl+0 would change it back to flat. I would also like this to work in object mode.

Is this possible (perhaps with a script bound to a shortcut)?

Update: I think it’s not possible without writing an add-on.

Update 2: I'm terrible at coding, never ever used python, but reading the manual and some tutorials I've created an addon, and it works. If someone skilled in python would like to improve the script, please do so :)

So now in both edit and object mode I can use my own shortcuts, or the buttons on the tooltip to change the display of the selected object between

-Flat shading + subsurface 0 -Smooth shading + subsurface 3 This makes modelling for me a lot easier.

The code looks like this:

    bl_info = {
"name": "Smooth subsurface",
"category": "Object",
"blender": (2, 80, 0),
}

import bpy

class MyOperator(bpy.types.Operator):
"""Smooth display on"""
bl_idname = "scene.myoperator"
bl_label = "Smooth on"

def execute(self, context):
if context.active_object.mode == 'OBJECT':
bpy.ops.object.subdivision_set(level=3, relative=False)
else:
bpy.ops.mesh.select_all(action='SELECT')
bpy.context.object.modifiers["Subdivision"].levels = 3
bpy.ops.mesh.select_all(action='DESELECT')
return {"FINISHED"}

class MyOperator2(bpy.types.Operator):
"""Smooth display off"""
bl_idname = "scene.myoperator2"
bl_label = "Smooth off"

def execute(self, context):
if context.active_object.mode == 'OBJECT':
bpy.ops.object.subdivision_set(level=0, relative=False)
else:
bpy.ops.mesh.select_all(action='SELECT')
bpy.context.object.modifiers["Subdivision"].levels = 0
bpy.ops.mesh.select_all(action='DESELECT')
return {"FINISHED"}

class MyPanel(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Smooth mesh"
bl_idname = "SCENE_PT_layout"

def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("scene.myoperator")
layout = self.layout
row = layout.row()
row.operator("scene.myoperator2")

#bpy.utils.register_class(MyPanel)
#bpy.utils.register_class(MyOperator)
#bpy.utils.register_class(MyOperator2)

classes = (
MyPanel,
MyOperator,
MyOperator2,
)

register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
register()


Thank you, and happy blending! :)

• Can't you just add it to your quick menu (q)? I've got smooth/flat shading set up there. – AxiomDes Aug 8 '19 at 20:07
• I've tried that method earlier, I would just prefer turning on smoothing and subsurface modifier with one shortcut (much faster). – Grey Aug 8 '19 at 20:43
• If you are using left-click-default in Blender 2.8, shading smooth is as simple as right-clicking in the viewport and selecting it from the popup menu. – hatinacat2000 Aug 10 '19 at 14:50