Post #2105: I recommend typing out a script file and using PME to execute them. It’s an easy

📋 Metadata

  • Author: iceythe
  • Date: 2019-03-24 13:13:41
  • Type: answer
  • Quality Score: 8/10
  • Reply to: post_02103

🏷️ Tags

macro python-scripting intermediate advanced

  • Macro Editor
  • Python Scripting

💬 Content

I recommend typing out a script file and using PME to execute them. It’s an easy way of getting into python. This one toggles based on selection and supports multi-object toggling.

from bpy import context
mode = context.mode

if 'OBJECT' in mode:
    objs = context.selected_objects
elif 'EDIT_MESH' in mode:
    uniques = context.objects_in_mode_unique_data
    objs = [o for o in uniques if o.data.total_vert_sel]

mods = [m for o in objs for m in o.modifiers if 'SUBSURF' in m.type]

if mods:
    for idx, mod in enumerate(mods):
        if idx is 0:
            toggle = mod.show_viewport
        mod.show_viewport = not toggle

If you prefer a one-liner for easy drop in PME (these are terrible to read):

S = C.selected_objects if 'OBJ' in C.mode else [o for o in C.objects_in_mode_unique_data if o.data.total_vert_sel]; M = [m for o in S for m in o.modifiers if 'SURF' in m.type]; tgl = M[0].show_viewport if M else None; [setattr(m, 'show_viewport', not tgl) for m in M]

❤️ 2 likes


🔗 View on Blender Artists