Adding modifiers in Python
The Python class of Blender objects contains a modifiers
attribute. Like all collections, modifiers
provides the new
method, which creates and returns new items. By using new
, we can automate the setup of modifiers using Python.
Finding collection-type items
Object.modifiers.new
takes two arguments: name
and type
. The first will be displayed in the modifier properties in the interface, while type
specifies which kind of modifier we want to create. The type
argument must belong to the list of available types, or it will cause an error. Available types are listed in the API documentation:
https://docs.blender.org/api/3.3/bpy_types_enum_items/object_modifier_type_items.html
But we can also get them from Blender itself. These commands will list the modifier keywords in Blender’s Python console:
>>> import bpy >>> mod_rna = bpy.types.ObjectModifiers.bl_rna >>> mod_params = mod_rna.functions["new"].parameters...