Modifier removal
To remove a modifier from an object.
obj below is a reference to an object either obtained via
obj = bpy.context.active_object
obj = bpy.context.object
# or
obj = bpy.data.objects[name]
If you want to remove a modifier it is done by name, not by type. You could have multiple array modifiers, but only want to remove
a specific one.
modifier_to_remove = obj.modifiers.get("Bevel")
obj.modifiers.remove(modifier_to_remove)
# or as a one-liner
obj.modifiers.remove(obj.modifiers.get("Bevel"))
# or remove all modifiers from an object
obj.modifiers.clear()
Modifier Apply
Using an operator
As sambler pointed out
# operates on all selected objects (not just the scene's _active_object_)
bpy.ops.object.convert(target='MESH')
lower level
If you want to apply all modifiers it's covered here: How to get a new mesh with modifiers applied using Blender Python API? - This involves using obj.to_mesh and there are a few things to consider, it:
- generates a new mesh from your current
obj (leaves current obj.data intact)
- does not remove the modifiers automatically from the object. (unlike the Apply button on the Modifiers panel, or Convert to Mesh).
This snippet will:
"""
- make a reference to the current obj.data ( i call it old_mesh)
- make a new Mesh ( new_mesh) using the effect of the combined modifiers on `obj`
- remove all modifiers from `obj`
- assign the new Mesh to obj.data
- remove old_mesh from the blend
"""
in code:
import bpy
context = bpy.context
scene = context.scene
obj = context.object
# get a reference to the current obj.data
old_mesh = obj.data
# settings for to_mesh
apply_modifiers = True
settings = 'PREVIEW'
new_mesh = obj.to_mesh(scene, apply_modifiers, settings)
# object will still have modifiers, remove them
obj.modifiers.clear()
# assign the new mesh to obj.data
obj.data = new_mesh
# remove the old mesh from the .blend
bpy.data.meshes.remove(old_mesh)
bpy.ops.object.convert(target='MESH')this is the operator called when using Alt-C -> Mesh from curve – sambler Jan 08 '16 at 15:06