Blender  V3.3
Classes
BPY_extern_run.h File Reference
#include "BLI_sys_types.h"
#include "BLI_compiler_attrs.h"

Go to the source code of this file.

Classes

struct  BPy_RunErrInfo
 

Functions

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 BPY_run_filepath (struct bContext *C, const char *filepath, struct ReportList *reports) ATTR_NONNULL(1
 
bool bool BPY_run_text (struct bContext *C, struct Text *text, struct 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 BPY_run_string_exec (struct bContext *C, const char *imports[], const char *expr)
 
bool BPY_run_string_eval (struct bContext *C, const char *imports[], const char *expr)
 
Run a String as a Script & Return the Result

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

bool BPY_run_string_as_number (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, double *r_value) ATTR_NONNULL(1
 
bool bool BPY_run_string_as_intptr (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, intptr_t *r_value) ATTR_NONNULL(1
 
bool bool bool BPY_run_string_as_string_and_size (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_size) ATTR_NONNULL(1
 
bool bool bool bool BPY_run_string_as_string (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
 

Detailed Description

Common Arguments

Definition in file BPY_extern_run.h.

Function Documentation

◆ BPY_run_filepath()

bool BPY_run_filepath ( struct bContext C,
const char *  filepath,
struct ReportList reports 
)

Execute filepath as a Python script.

Wrapper for PyRun_File (similar to calling python with a script argument). Used for the --python command line argument.

Parameters
CThe context (never NULL).
filepathThe file path to execute.
reportsFailure to execute the script will report the exception here (may be NULL).
Returns
true on success, otherwise false with an error reported to reports.
Note
Python scripts could consider bpy.utils.execfile, which has the advantage of returning the object as a module for data access & caching pyc file for faster re-execution.

Referenced by arg_handle_python_file_run(), Freestyle::PythonInterpreter::interpretFile(), and run_pyfile_exec().

◆ BPY_run_string_as_intptr()

bool bool BPY_run_string_as_intptr ( struct bContext C,
const char *  imports[],
const char *  expr,
struct BPy_RunErrInfo err_info,
intptr_t r_value 
)

Evaluate expr as an integer or pointer.

Note
Support both int and pointers.
Parameters
CSee Common Arguments.
importsSee Common Arguments.
exprThe expression to evaluate.
err_infoSee Common Arguments.
r_valueThe resulting value.
Returns
Success.

Referenced by ui_tooltip_data_from_tool().

◆ BPY_run_string_as_number()

bool BPY_run_string_as_number ( struct bContext C,
const char *  imports[],
const char *  expr,
struct BPy_RunErrInfo err_info,
double r_value 
)

Evaluate expr as a number (double).

Parameters
CSee Common Arguments.
importsSee Common Arguments.
exprThe expression to evaluate.
err_infoSee Common Arguments.
r_valueThe resulting value.
Returns
Success.

Referenced by ui_number_from_string(), and user_string_to_number().

◆ BPY_run_string_as_string()

bool bool bool bool BPY_run_string_as_string ( struct bContext C,
const char *  imports[],
const char *  expr,
struct BPy_RunErrInfo err_info,
char **  r_value 
)

◆ BPY_run_string_as_string_and_size()

bool bool bool BPY_run_string_as_string_and_size ( struct bContext C,
const char *  imports[],
const char *  expr,
struct BPy_RunErrInfo err_info,
char **  r_value,
size_t *  r_value_size 
)

Evaluate expr as a string.

Parameters
CSee Common Arguments.
importsSee Common Arguments.
exprThe expression to evaluate.
err_infoSee Common Arguments.
r_valueThe resulting value.
Returns
Success.

Referenced by ui_tooltip_data_from_tool().

◆ BPY_run_string_eval()

bool BPY_run_string_eval ( struct bContext C,
const char *  imports[],
const char *  expr 
)

◆ BPY_run_string_exec()

bool BPY_run_string_exec ( struct bContext C,
const char *  imports[],
const char *  expr 
)

Run an entire script, matches: exec(compile(..., "exec"))

Definition at line 307 of file bpy_interface_run.c.

References bpy_run_string_impl(), and C.

Referenced by arg_handle_addons_set(), arg_handle_python_expr_run(), script_reload_exec(), and wm_file_read_post().

◆ BPY_run_text()

bool bool BPY_run_text ( struct bContext C,
struct Text text,
struct ReportList reports,
bool  do_jump 
)

Execute a Blender text block as a Python script.

Wrapper for Py_CompileStringObject & PyEval_EvalCode. Used for the --python-text command line argument.

Parameters
CThe context (never NULL).
textThe text-block to execute.
reportsFailure to execute the script will report the exception here (may be NULL).
do_jumpWhen true, any error moves the cursor to the location of that error. Useful for executing scripts interactively from the text editor.
Returns
true on success, otherwise false with an error reported to reports.
Note
The __file__ is constructed by joining the blend file-path to the name of the text. This is done so error messages give useful output however there are rare cases causes problems with introspection tools which attempt to load __file__.

Referenced by arg_handle_python_text_run(), BPY_modules_load_user(), Freestyle::PythonInterpreter::interpretFile(), Freestyle::PythonInterpreter::interpretText(), and text_run_script().