6
$\begingroup$

I have been searching on Internet for a while and I only have found this piece of code (from this site)

import bpy

scene = bpy.context.scene
for o in scene.objects:
    if o.type == 'MESH':
    for m in o.modifiers:
        bpy.ops.object.modifier_remove(modifier="Smoke")

But it didn´t work for me. It only removes the modifier from the active object, not for all the objects in the scene.

What am I doing wrong?

Thanks pals.

$\endgroup$
5
$\begingroup$

Many operators work on only the active object and some will work on all selected objects, removing a modifier is a case of only working on the active object, the active object is the one that has it's properties displayed so is the only one with a visible modifier list.

You can delete modifiers without using operators, this way you don't have to change the active object and it also doesn't matter if the modifier has been renamed.

import bpy

scene = bpy.context.scene
for o in scene.objects:
    if o.type == 'MESH':
        for m in o.modifiers:
            if m.type == 'SMOKE':
                o.modifiers.remove(m)
| improve this answer | |
$\endgroup$
3
$\begingroup$

The following only addresses the case where it is desired all objects in a specific set to have the same modifier. It does not address the case where deleting one or all instances of a specific type of modifier, i.e. "Smoke", from a set of objects which may have completely different sets and permutations of modifiers.

  1. Enable the Copy Attributes Add-on. Where to find the Copy Attributes Add-on in Blender User Preferences
    1. Remove all or specific modifiers from one of the objects.
    2. Select all objects you want to remove the modifiers from, with the one without modifiers being the last (active).
    3. Ctrl+C, "Copy Modifiers"
| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ You can do this directly with the Ctrl+Lmenu Link > Modifiers no addons needed $\endgroup$ – Duarte Farrajota Ramos Feb 12 '18 at 0:38
1
$\begingroup$

try setting every mesh object as active one by one

import bpy

scene = bpy.context.scene
for o in scene.objects:
    if o.type == 'MESH':
        bpy.context.scene.objects.active = o
        bpy.ops.object.modifier_remove(modifier="Smoke")
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.