Blender 4.2 LTS: Python API¶
Add-on Packaging¶
With the new extensions platform, there is also a new method for packaging add-ons.
It uses a separate blender_manifest.toml file instead of bl_info embedded in the script.
See the
extensions user manual
for details.
The old packaging still works but is considered legacy, and add-ons are recommended to switch to the new manifest file.
Additions¶
Online Access¶
bpy.app.online_accessis a read-only property to check whether Blender (and add-ons) is expected to access the internet.- Add-ons are expected to check for this property before accessing the internet. See documentation.
- Also available is
bpy.app.online_access_overridewhich tells whether Blender was launched with--offline-mode/--online-mode.
bpy.app Module¶
- Added
bpy.app.python_argsto support calling Python in an environment matching Blender's Python environment. (14b03fca3c). Note: this was back-ported to 4.2.1 and is not available in 4.2.0.
bpy.utils Module¶
- The
EXTENSIONSoption has been added tobpy.utils.user_resource()(dc9430c480). - Add
bpy.utils.register_cli_command&unregister_cli_commandso scripts can define their own command line functionality via (-c,--command). (9372e0dfe0) - Add
bpy.utils.extension_path_user(__package__, path="", create=False)(96906536db).
Animation¶
rna_struct.keyframe_insert()now has a new, optional keyword argumentkeytypeto set the key type (1315991ecb). This makes it possible to set the new key's type directly. Example:bpy.context.object.keyframe_insert("location", keytype='JITTER').- There is a new function on the F-Curve:
bake. This creates keys at a given interval for a given range on the existing curve (20a4c9c928).
Layout Panels¶
Added support for layout panels for operator properties drawing, in popups, redo panel and the file browser sidebar. Add-ons are recommended to use panels for organizing properties now, to follow Blender user interface conventions. (aa03646a74, 02681bd44d)
Exporters¶
Exporter add-ons can add support for the new
Collection Exporters.
This requires a FileHandler
with bl_export_operator, and a string property named collection
on the operator to indicate the collection to export.
See the FBX and glTF add-ons for an example.
Modal Operators¶
Window.modal_operatorsprovides a list of running modal operators. (#122193)- Modal operator can add
MODAL_PRIORITYtobl_optionsto handle events before other modal operators. (6efd7a6a50)
Handlers¶
- Render: include info string for "render_stats" handler (fcc481a407)
UI¶
- Add support defaulting to cancel for operator confirm/cancel buttons:
WindowManager.invoke_props_dialog(..., cancel_dfault=False)(1cfc83d5f6). - Add
Region.tag_refresh_uito support refreshing popups such as popovers or operator dialogs (fa27d2fe65). - Add
Context.region_popupto access the region of a popup (742a8b47cd).
Breaking changes¶
Statically Typed IDProperties¶
IDProperties have never be statically typed before, modifying their type was (way) too easy from Python. A mere assignment of a float value to an IDProperty from Python code would e.g. convert that property to a 'double' one. This was especially problematic for system-defined IDProperties (i.e. these used as backend storage for internal Blender data, like geometry node modifier properties, or Python-defined 'dynamic RNA' properties). It would also easily break library overrides, which cannot give useful results when the type of the reference and override data differs.
The following IDProperties now have a fixed, static type that cannot be modified from the python API. In array (vector) cases, the length is also considered as part of the type, and therefore fixed.
- System-defined:
- Geometry Node modifier settings IDProperties.
- Python-defined properties (through the
bpy.props.module).
- User-defined:
- Properties created from the UI (
Custom Propertiespanel, in thePropertieseditor), when theirLibrary Overridableoption is enabled.
- Properties created from the UI (
When assigning a value to such property, a 'reasonable conversion' is attempted if possible (e.g. an integer can be converted to a float, but a float cannot be assigned to an integer IDProperty), otherwise the assignment fails.
Note
Technically, this is a breaking change. In particular in Geometry Nodes modifier case, where the 'expected' way to access these data from python is currently through 'raw' IDProperty path. However, practically, no 'valid' usages of the IDProperties should be broken by it.
Further details can be found in the design task.
Commits: 4d1fe98604, b278e37f70, 76f03eb141, 9c41bf4fa2
bpy.utils Module¶
- The
AUTOSAVEoption has been removed frombpy.utils.user_resource()(6bfc8612bf).
Render Settings¶
- EEVEE identifier has been changed to
BLENDER_EEVEE_NEXT - Motion Blur settings have been de-duplicated between Cycles and EEVEE and moved to
bpy.types.RenderSettings. (74b8f99b43)scene.cycles.motion_blur_position->scene.render.motion_blur_positionscene.eevee.use_motion_blur->scene.render.user_motion_blurscene.eevee.motion_blur_position->scene.render.motion_blur_positionscene.eevee.motion_blur_shutter->scene.render.motion_blur_shutter
- Light cast shadow setting have been de-duplicated between Cycles and EEVEE and moved to
bpy.types.Light. (1036d9bdb2)light.cycles.cast_shadow->light.use_shadow
- Bloom has been deprecated in EEVEE. (#123059)
view_layer.eevee.use_pass_bloomscene.eevee.use_bloomscene.eevee.bloom_thresholdscene.eevee.bloom_colorscene.eevee.bloom_kneescene.eevee.bloom_radiusscene.eevee.bloom_clampscene.eevee.bloom_intensity
- EEVEE (pre 4.2) specific Material settings have been deprecated or aliased where possible.
(c7807a425a)
bpy.types.Material.blend_method=>bpy.types.Material.surface_render_method. 'Opaque' and 'Alpha Clip' maps to deferred.show_transparent_backhas been renamed touse_transparency_overlap.use_screen_refractionhas been renamed touse_raytrace_refraction.use_sss_translucencyanduse_sss_translucencyhave been deprecated.
- Light probe API has been changed. (6a71a91b83)
- Each light probe type now has its own type ()
grid_prefix has been removed and access has been limited to volume probes.- Parallax and other sphere probe only properties are be limited to sphere probes.
visibilityproperties have been deprecated.
- Deprecated shadow settings
shadow_cube_sizeandshadow_cascade_sizeare not used anymore and will be removed in a future release.
Nodes¶
- Unused
parentargument removed from theNodeTreeInterface.new_panelfunction for creating node group panels. (#118792) - Some node properties have been renamed to fix name collisions
(deb332601c):
- Compositor Box/Ellipse Mask node:
width->mask_width(same forheight) - Shader AOV Output node:
name->aov_name - Geometry Color node:
color->value
- Compositor Box/Ellipse Mask node:
Image Object Operators¶
- The "add image object" operator has been deduplicated and unified into one operator:
object.empty_image_add. (013cd3d1ba)
Previously there were two operators to add image empties (object.load_reference_imageandobject.load_background_image) with a separate operator for dropping (object.drop_named_image). - The "add/remove background image from camera" operator has been renamed to clarify that this is
only for the camera object (013cd3d1ba):
view3d.background_image_add->view3d.camera_background_image_add.view3d.background_image_remove->view3d.camera_background_image_remove.