A script.
As answered by @michaelh Please accept that answer if using modifier tools addon answers your question
There is an existing addon modifier tools to multi set all modifiers in the stack of the context object.
For multiple objects.
Misread question, as to setting all modifiers on multiple objects.
Iterate over selected objects and set show in render and viewport to True
if option = 'ENABLE'
, false with 'DISABLE'
or toggle value.
import bpy
from bpy import context
option = 'TOGGLE' # in 'ENABLE', 'DISABLE', 'TOGGLE'
for ob in context.selected_objects:
for mod in getattr(ob, "modifiers", []):
if option == 'TOGGLE':
mod.show_viewport = not mod.show_viewport
else:
mod.show_viewport = option == 'ENABLE'
# optional
#mod.show_render = mod.show_viewport # keep same
Note will disable for any option
not in 'ENABLE', 'TOGGLE'