You can get it using Python.
I used a template "Operator Simple". And I added subsurf and smooth to an object to know the names of this functions:
Next, I replaced default main() function by this functions:
def main(context):
bpy.ops.object.subdivision_set(level=2)
bpy.ops.object.shade_smooth()
It gives subsurf and smoth, but never gets back.
To create a toggle, you need to know about programming. I writed this code:
def main(context):
test=True
for md in context.active_object.modifiers:
if(md.type=='SUBSURF'):
if(md.levels==2):
test=False;
break
if(test):
bpy.ops.object.subdivision_set(level=2)
bpy.ops.object.shade_smooth()
else:
bpy.ops.object.subdivision_set(level=0)
bpy.ops.object.shade_flat()
It checks for subsurf level 2, and if finds, removes Subsurf and smooth.
Finally, I can use this function by finding it in spacebar menu:
Also, you can add sourtcut:
UPD: For making it works in Edit Mode
You noted what script doesn't work in Edit Mode. It is because shade_smooth() doesn't work in Edit Mode. So lets try to enter Object Mode, do subsurf and smooth operations and return to edit mode.
Get the current mode, and save:
if(context.mode!='OBJECT'):
returnto=context.mode
Return to edit mode:
if(returnto):
bpy.ops.object.mode_set(mode=returnto)
Full code
(you can save it as .py file and install it like add-on):
bl_info = {
"name": "Subsmoth",
"author": "Subsmoth",
"version": (1, 0),
"blender": (2, 78, 0),
"location": "",
"description": "Toggle Subsurf and smooth",
"warning": "",
"wiki_url": "",
"category": "3D View",
}
import bpy
def main(context):
test=True
for md in context.active_object.modifiers:
if(md.type=='SUBSURF'):
if(md.levels==2):
test=False;
break
returnto=False
if(context.mode!='OBJECT'):
returnto=context.mode
if(returnto=='EDIT_MESH'):
returnto='EDIT'
bpy.ops.object.mode_set(mode='OBJECT')
if(returnto=='EDIT' or returnto==False):
if(test):
bpy.ops.object.subdivision_set(level=2)
bpy.ops.object.shade_smooth()
else:
bpy.ops.object.subdivision_set(level=0)
bpy.ops.object.shade_flat()
if(returnto):
bpy.ops.object.mode_set(mode=returnto)
class SubsmothOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.subsmooth"
bl_label = "Subsmoth"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SubsmothOperator)
def unregister():
bpy.utils.unregister_class(SubsmothOperator)
if __name__ == "__main__":
register()