Is anyone aware of a script that toggles the Visibility of the Subdivision Surface Modifiers for all Objects in the Scene?
In the Display Tools Addon is a script to toggle the Visibility for the active object but not for all at the same time unfortunately.
The Display Tools Script looks like this:
#Display Modifiers Viewport ondef modifiers_viewport_on(context):
selection = bpy.context.selected_objects
if not(selection):
for obj in bpy.data.objects:
for mod in obj.modifiers:
mod.show_viewport = True
else:
for obj in selection:
for mod in obj.modifiers:
mod.show_viewport = True
class DisplayModifiersViewportOn(bpy.types.Operator):
'''Display modifiers in viewport'''
bl_idname = "view3d.display_modifiers_viewport_on"
bl_label = "On"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
modifiers_viewport_on(context)
return {'FINISHED'}
#Display Modifiers Viewport off
def modifiers_viewport_off(context):
selection = bpy.context.selected_objects
if not(selection):
for obj in bpy.data.objects:
for mod in obj.modifiers:
mod.show_viewport = False
else:
for obj in selection:
for mod in obj.modifiers:
mod.show_viewport = False
class DisplayModifiersViewportOff(bpy.types.Operator):
'''Hide modifiers in viewport'''
bl_idname = "view3d.display_modifiers_viewport_off"
bl_label = "Off"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
modifiers_viewport_off(context)
return {'FINISHED'}
Just found a toggle that works for selected objects but only in object mode.
It would be nice to have this script work in edit mode as well and make it work for all objects in the scene.
def ss_optimal(): sel = bpy.context.selected_objects
act_obj = bpy.context.active_object
if act_obj.type == 'MESH' or act_obj.type == 'CURVE' or act_obj.type == 'FONT' or act_obj.type == 'META' or act_obj.type == 'SURFACE':
for mod in act_obj.modifiers:
if mod.type == 'SUBSURF':
optimal = not(mod.show_only_control_edges)
break
else: optimal = False
for obj in sel:
if obj.type == 'MESH' or obj.type == 'CURVE' or obj.type == 'FONT' or obj.type == 'META' or obj.type == 'SURFACE':
for mod in obj.modifiers:
if mod.type == 'SUBSURF':
mod.show_only_control_edges = optimal
class OBJECT_OT_ss_optimal(bpy.types.Operator):
bl_idname = "object.ss_optimal"
bl_label = "Toggle Optimal Display"
bl_options = {'REGISTER'}
def execute(self, context):
ss_optimal()
return {'FINISHED'}
Do you want to use this within a game, or just while you are modeling or animating? If it is not within a game environment, just go into the scene tab, scroll down to the bottom, check simplify and turn the subdivisions to 0.
@ randy:
thanks for the script ^^ it works really great but i’d rather be able to toggle the modifier instead of setting it to a certain subd level.
because then the objects could have different subd levels and i could still toggle the modifier
@harley
i’d like to use it for modeling because sometimes its easier to see certain things without subd’s
i tried something like this now but it doesn’t work of course
bl_info = { "name": "GlobalSubDToggle",
"location": "File/UserPrefs/Input Add new key in 3D View 'object.GlobalSubDToggle'",
"description": "GlobalSubDToggle",
"category": "Mesh",
}
import bpy
class zzz(bpy.types.Operator):
"""GlobalSubDToggle""" # blender will use this as a tooltip for menu items and buttons.
bl_idname = "object.GlobalSubDToggle" # unique identifier for buttons and menu items to reference.
bl_label = "GlobalSubDToggle" # display name in the interface.
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): # execute() is called by blender when running the operator.
# The original script
if obj.type == 'MESH' or obj.type == 'CURVE' or obj.type == 'FONT' or obj.type == 'META' or obj.type == 'SURFACE':
for mod in obj.modifiers:
if mod.type == 'SUBSURF':
optimal = not(mod.show_only_control_edges)
break
else: optimal = False
for obj in sel:
if obj.type == 'MESH' or obj.type == 'CURVE' or obj.type == 'FONT' or obj.type == 'META' or obj.type == 'SURFACE':
for mod in obj.modifiers:
if mod.type == 'SUBSURF':
mod.show_only_control_edges = optimal
return {'FINISHED'} # this lets blender know the operator finished successfully.
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
register()
yes, seems like he is looking for almost the same thing.
what i’d really like to have is that this button toggles the visibility of the subd modifier for all subtools in the scene though.
thanks for looking into it randy
It will work as-is and should do what I think you want. I still need to add in a few bits of text (tooltips, etc) and take a look at some of the code (maybe better way to do parts of it), but it works well for now.
Over the next few days I’ll look into what I mentioned above, in the mean time, test it and tell me if you need anything else from the script. Then when it’s done, I release the new version properly…
I thought the same thing Ron. Setting the subdivision surface to 0 has the same visual effect as turning off the “eye” icon.
import bpy
scene = bpy.data.scenes[0]
for ob in scene.objects:
if len(ob.modifiers) > 0:
for m in ob.modifiers:
if m.type == 'SUBSURF':
# NOTE: change show flag to which ever you want. (see doc URL)
if m.show_viewport:
m.show_viewport = False
else:
m.show_viewport = True
Oooppss I forgot about that detail. I guess it’s senseless at this point, as you have what you need now, but I’ve fixed my script to not change the levels if desired. Here’s a screenshot: