Skip to main content
added 347 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

A script.

BelowAs answered by @michaelh Please accept that answer if using modifier tools addon answers your question

There is a test script, towards creating an operator, an hence anexisting 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_rendershow_viewport = not mod.show_rendershow_viewport
        else:
            mod.show_rendershow_viewport = option == 'ENABLE'
        mod# optional
        #mod.show_viewportshow_render = mod.show_rendershow_viewport # keep same

Note will disable for any option not in 'ENABLE', 'TOGGLE'

A script.

Below is a test script, towards creating an operator, an hence an addon.

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_render = not mod.show_render
        else:
            mod.show_render = option == 'ENABLE'
        mod.show_viewport = mod.show_render # keep same

Note will disable for any option not in 'ENABLE', 'TOGGLE'

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'

Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

A script.

Below is a test script, towards creating an operator, an hence an addon.

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_render = not mod.show_render
        else:
            mod.show_render = option == 'ENABLE'
        mod.show_viewport = mod.show_render # keep same

Note will disable for any option not in 'ENABLE', 'TOGGLE'