Blender V5.3
bpy_interface_run.cc File Reference
#include <cstdio>
#include <optional>
#include <Python.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.hh"
#include "BLI_function_ref.hh"
#include "BLI_listbase.hh"
#include "BLI_path_utils.hh"
#include "BLI_string.hh"
#include "BLI_string_utils.hh"
#include "BKE_context.hh"
#include "BKE_idprop.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_report.hh"
#include "BKE_text.h"
#include "DNA_text_types.h"
#include "BPY_extern.hh"
#include "BPY_extern_run.hh"
#include "bpy_capi_utils.hh"
#include "bpy_traceback.hh"
#include "../generic/idprop_py_api.hh"
#include "../generic/py_capi_utils.hh"

Go to the source code of this file.

Namespaces

namespace  blender
 BMesh Iterators.

Functions

Private Utilities
static void blender::python_script_error_jump_text (Text *text, const char *filepath)
static void blender::bpy_text_filepath_get (char *filepath, const size_t filepath_maxncpy, const Main *bmain, const Text *text)
static PyObject * blender::python_compat_wrapper_PyRun_FileExFlags (FILE *fp, const char *filepath, const int start, PyObject *globals, PyObject *locals, const int closeit, PyCompilerFlags *flags)
static bool blender::python_script_exec (bContext *C, const char *filepath, Text *text, ReportList *reports, const bool do_jump)
Run File/Text as a Script
Note
BPY_run_filepath and BPY_run_filepath have almost identical behavior one operates on a file-path, the other on a blender text-block.
bool blender::BPY_run_filepath (bContext *C, const char *filepath, ReportList *reports) ATTR_NONNULL(1
bool bool blender::BPY_run_text (bContext *C, Text *text, ReportList *reports, bool do_jump) ATTR_NONNULL(1
Run a String as a Script
  • Use 'eval' for simple single-line expressions.
  • Use 'exec' for full multi-line scripts.
bool blender::BPY_string_compile_check (const char *expr)
bool blender::BPY_run_string_eval (bContext *C, const char *imports[], const char *expr)
bool blender::BPY_run_string_exec (bContext *C, const char *imports[], const char *expr)
bool blender::BPY_run_string_exec_with_locals (bContext *C, StringRefNull script, IDProperty &locals)
std::optional< IDProperty * > blender::BPY_run_string_exec_with_locals_return_idprop (bContext *C, StringRefNull script, IDProperty &locals, StringRefNull result_var_name)
Run Text / Filename / String
static void blender::bpy_run_with_context_or_null (bContext *C, FunctionRef< void()> fn)
static bool blender::bpy_run_string_impl (bContext *C, const char *imports[], const char *expr, const int mode)
static IDProperty * blender::pyobject_to_idprop (const StringRefNull prop_name, PyObject *py_object)
static bool blender::bpy_run_string_exec_with_locals_assume_gil (const StringRefNull script, IDProperty &locals, FunctionRef< void(PyObject *py_locals)> on_exec_ok)
static bool blender::bpy_run_string_exec_with_locals_acquire_gil (bContext *C, const StringRefNull script, IDProperty &locals, FunctionRef< void(PyObject *py_locals)> on_exec_ok)
Run Python & Evaluate Utilities

Return values as plain C types, useful to run Python scripts in code that doesn't deal with Python data-types.

static void blender::run_string_handle_error (BPy_RunErrInfo *err_info)
Run a String as a Script & Return the Result

Convenience functions for executing a script and returning the result as an expected type.

bool blender::BPY_run_string_as_number (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, double *r_value) ATTR_NONNULL(1
bool bool bool blender::BPY_run_string_as_string_and_len (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len) ATTR_NONNULL(1
bool bool bool bool blender::BPY_run_string_as_string (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
bool bool bool bool bool blender::BPY_run_string_as_string_and_len_or_none (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len) ATTR_NONNULL(1
bool bool bool bool bool bool blender::BPY_run_string_as_string_or_none (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
bool bool blender::BPY_run_string_as_intptr (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, intptr_t *r_value) ATTR_NONNULL(1