35 #include "../generic/py_capi_utils.h"
36 #include "../generic/python_utildefines.h"
57 #define BPY_RELEASE_GIL
61 const char *opname = PyUnicode_AsUTF8(value);
63 PyErr_Format(PyExc_TypeError,
"%s() expects a string argument", py_fn_id);
69 PyErr_Format(PyExc_KeyError,
"%s(\"%s\") not found", py_fn_id, opname);
79 PyObject *context_dict =
NULL;
80 const char *context_str =
NULL;
90 PyErr_SetString(PyExc_RuntimeError,
"Context is None, cant poll any operators");
94 if (!PyArg_ParseTuple(args,
"s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) {
101 PyErr_Format(PyExc_AttributeError,
102 "Polling operator \"bpy.ops.%s\" error, "
103 "could not be found",
111 PyErr_Format(PyExc_TypeError,
112 "Calling operator \"bpy.ops.%s.poll\" error, "
113 "expected a string enum in (%s)",
121 if (
ELEM(context_dict,
NULL, Py_None)) {
124 else if (!PyDict_Check(context_dict)) {
125 PyErr_Format(PyExc_TypeError,
126 "Calling operator \"bpy.ops.%s.poll\" error, "
127 "custom context expected a dict or None, got a %.200s",
129 Py_TYPE(context_dict)->tp_name);
134 if (context_dict !=
NULL) {
136 Py_INCREF(context_dict);
142 if (context_dict !=
NULL) {
144 if (context_dict_test != context_dict) {
145 Py_DECREF(context_dict_test);
149 Py_DECREF(context_dict);
153 return Py_INCREF_RET(
ret);
164 const char *context_str =
NULL;
166 PyObject *context_dict =
NULL;
177 PyErr_SetString(PyExc_RuntimeError,
"Context is None, cant poll any operators");
181 if (!PyArg_ParseTuple(args,
182 "sO|O!si:_bpy.ops.call",
195 PyErr_Format(PyExc_AttributeError,
196 "Calling operator \"bpy.ops.%s\" error, "
197 "could not be found",
203 PyErr_Format(PyExc_RuntimeError,
204 "Calling operator \"bpy.ops.%s\" error, "
205 "can't modify blend data in this state (drawing/rendering)",
213 PyErr_Format(PyExc_TypeError,
214 "Calling operator \"bpy.ops.%s\" error, "
215 "expected a string enum in (%s)",
223 if (
ELEM(context_dict,
NULL, Py_None)) {
226 else if (!PyDict_Check(context_dict)) {
227 PyErr_Format(PyExc_TypeError,
228 "Calling operator \"bpy.ops.%s\" error, "
229 "custom context expected a dict or None, got a %.200s",
231 Py_TYPE(context_dict)->tp_name);
241 if (context_dict !=
NULL) {
243 Py_INCREF(context_dict);
248 PyErr_Format(PyExc_RuntimeError,
249 "Operator bpy.ops.%.200s.poll() %.200s",
251 msg ? msg :
"failed, context is incorrect");
259 if (kw && PyDict_Size(kw)) {
261 &
ptr, kw,
false,
"Converting py args to operator properties: ");
264 if (error_val == 0) {
272 #ifdef BPY_RELEASE_GIL
278 PyThreadState *ts = PyEval_SaveThread();
283 #ifdef BPY_RELEASE_GIL
285 PyEval_RestoreThread(ts);
314 PyErr_Format(PyExc_AttributeError,
"Operator \"%s\" does not take any args", opname);
323 if (context_dict !=
NULL) {
325 if (context_dict_test != context_dict) {
326 Py_DECREF(context_dict_test);
330 Py_DECREF(context_dict);
334 if (error_val == -1) {
355 bool all_args =
true;
356 bool macro_args =
true;
365 PyErr_SetString(PyExc_RuntimeError,
366 "Context is None, cant get the string representation of this object.");
370 if (!PyArg_ParseTuple(args,
371 "s|O!O&O&:_bpy.ops.as_string",
385 PyErr_Format(PyExc_AttributeError,
386 "_bpy.ops.as_string: operator \"%.200s\" "
387 "could not be found",
396 if (kw && PyDict_Size(kw)) {
398 &
ptr, kw,
false,
"Converting py args to operator properties: ");
401 if (error_val == 0) {
407 if (error_val == -1) {
412 pybuf = PyUnicode_FromString(buf);
416 pybuf = PyUnicode_FromString(
"");
433 PyList_SET_ITEM(list, i, PyUnicode_FromString(
ot->
idname));
449 return (PyObject *)pyrna;
473 PyModuleDef_HEAD_INIT,
void CTX_py_state_push(bContext *C, struct bContext_PyState *pystate, void *value)
void * CTX_py_dict_get(const bContext *C)
const char * CTX_wm_operator_poll_msg_get(struct bContext *C)
void CTX_py_state_pop(bContext *C, struct bContext_PyState *pystate)
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
void BKE_reports_clear(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
void BLI_ghashIterator_step(GHashIterator *ghi)
BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_ghash_len(GHash *gh) ATTR_WARN_UNUSED_RESULT
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
void BPY_modules_update(void)
Read Guarded memory(de)allocation.
char * BPy_enum_as_string(const EnumPropertyItem *item)
void BPy_reports_write_stdout(const ReportList *reports, const char *header)
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool clear)
struct bContext * BPY_context_get(void)
static wmOperatorType * ot_lookup_from_py_string(PyObject *value, const char *py_fn_id)
static PyObject * pyop_getrna_type(PyObject *UNUSED(self), PyObject *value)
static struct PyModuleDef bpy_ops_module
static PyObject * pyop_as_string(PyObject *UNUSED(self), PyObject *args)
static PyObject * pyop_dir(PyObject *UNUSED(self))
static struct PyMethodDef bpy_ops_methods[]
PyObject * BPY_operator_module(void)
static PyObject * pyop_poll(PyObject *UNUSED(self), PyObject *args)
static PyObject * pyop_call(PyObject *UNUSED(self), PyObject *args)
static PyObject * pyop_get_bl_options(PyObject *UNUSED(self), PyObject *value)
PyObject * PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args)
PyObject * pyrna_enum_bitfield_to_py(const EnumPropertyItem *items, int value)
bool pyrna_write_check(void)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const bool all_args, const char *error_prefix)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
int PyC_ParseBool(PyObject *o, void *p)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
const EnumPropertyItem rna_enum_operator_context_items[]
const EnumPropertyItem rna_enum_operator_type_flag_items[]
const EnumPropertyItem rna_enum_operator_return_items[]
struct SELECTID_Context context
bool WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context)
int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
int WM_operator_call_py(bContext *C, wmOperatorType *ot, short context, PointerRNA *properties, ReportList *reports, const bool is_undo)
void WM_operatortype_iter(GHashIterator *ghi)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
char * WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, const bool macro_args, wmOperatorType *ot, PointerRNA *opptr)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
void WM_operator_properties_free(PointerRNA *ptr)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)