s6.utils.blender

s6.utils.blender.execute_in_blender(blend_file: str, script_path: str, scene_name: str | None = None, blender_executable: str = 'blender', script_args: Iterable[str] | None = None, check: bool = True) CompletedProcess

Run a Python script inside Blender (background), forwarding stdout live.

The function launches Blender, opens the given .blend file, optionally switches to a specific scene, and executes the provided Python script within that Blender process. Blender’s stdout is streamed to the current process’s stdout as it is produced, while both stdout and stderr are captured and returned on completion.

Parameters:
  • blend_file (str) – Path to the .blend file to open.

  • script_path (str) – Path to the Python script (uses bpy) to execute inside Blender.

  • scene_name (Optional[str]) – Name of the scene to activate before the script runs.

  • blender_executable (str) – Path or command name of the Blender executable. Defaults to “blender” (looked up in PATH).

  • script_args (Optional[Iterable[str]]) – Extra arguments passed to the Python script after “–”. Inside Blender, access them via sys.argv after the “–” marker.

  • check (bool) – If True, raise CalledProcessError when Blender exits with a non-zero code.

Returns:

Contains args, returncode, stdout and stderr. Note that stdout is also forwarded live to the console during execution.

Return type:

subprocess.CompletedProcess

Raises:

subprocess.CalledProcessError – If check is True and Blender exits with a non-zero status.

s6.utils.blender.ensure_package(blender_executable: str, package_names: List[str]) None

Ensure Python packages are available in Blender’s bundled Python.

This helper locates Blender’s embedded Python interpreter, ensures pip is available, detects which requested packages appear importable, and then installs only the missing ones. Pip output is streamed live to the console for visibility.

Notes

  • Presence is determined via importlib.util.find_spec(name) using the provided strings. For distributions whose importable module name differs from the package name (e.g. Pillow installs as PIL), consider passing the importable module name to avoid unnecessary reinstalls.

  • Blender emits additional log lines when invoked; detection of the Python path is resilient to that and extracts the JSON line printed by the one-liner.

Parameters:
  • blender_executable (str) – Path or command name for the Blender executable.

  • package_names (List[str]) – Names to check/install. Each should be either an importable module name or a pip distribution identifier.

Raises:
  • subprocess.CalledProcessError – If probing Blender or ensuring pip fails.

  • RuntimeError – If the pip installation command exits with a non-zero status.

s6.utils.blender.run_blender_with_script(blend_file: str, script_path: str, scene_name: str | None = None, blender_executable: str = 'blender', script_args: Iterable[str] | None = None, check: bool = True) CompletedProcess

Deprecated alias for execute_in_blender.

This function forwards to execute_in_blender() for backward compatibility and may be removed in a future release.