Assigning and removing modifiers in Blender is done separately for each object. However, if we need to, for example, remove a modifier from many objects in a complex scene, removing them from each object individually will be long and inefficient. Using the Blender Python API, we can write a simple script that will remove modifiers from all selected objects in the scene.
First, we need to get the type of modifier that we want to remove from the objects.
For the currently active object in the scene, the type of its active modifier can be obtained as follows:
1 2 3 |
bpy.context.object.modifiers.active.type # SUBSURF |
Or by its number in the list of modifiers (remember that the list order starts with zero):
1 2 3 |
bpy.context.object.modifiers[1].type # SUBSURF |
Loop through all selected objects in the scene:
1 |
for obj in bpy.context.selected_objects: |
We can get a list of all modifiers for an object:
1 2 3 |
all_modifiers = [_modifier for _modifier in obj.modifiers] # [bpy.data.objects['Suzanne.002'].modifiers["Triangulate"], bpy.data.objects['Suzanne.002'].modifiers["Subdivision"], ...] |
But, we only want to remove modifiers of one type, so add a filter to the list.
1 2 3 |
subsurf_modifiers = [_modifier for _modifier in obj.modifiers if _modifier.type == 'SUBSURF'] # [bpy.data.objects['Suzanne.002'].modifiers["Subdivision"], ] |
Now we can remove modifiers from the object based on the resulting list.
1 2 |
for modifier in subsurf_modifiers: obj.modifiers.remove(modifier) |
All together:
1 2 3 4 |
for obj in bpy.context.selected_objects: subsurf_modifiers = [_modifier for _modifier in obj.modifiers if _modifier.type == 'SUBSURF'] for modifier in subsurf_modifiers: obj.modifiers.remove(modifier) |
Note that since we are removing modifiers by type and list, not by order number as we could do, even if multiple modifiers of the same type are applied to one object, all of them will be removed.