python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-04-01 12:43:07 +00:00
|
|
|
#include "bpy_operator_wrap.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BKE_context.h"
|
2009-01-02 07:54:38 +00:00
|
|
|
#include "BKE_report.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
2009-11-29 01:49:22 +00:00
|
|
|
#include "UI_interface.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "bpy_rna.h"
|
2008-12-28 08:41:49 +00:00
|
|
|
#include "bpy_util.h"
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
|
2009-06-18 19:51:22 +00:00
|
|
|
#include "../generic/bpy_internal_import.h" // our own imports
|
|
|
|
|
|
2009-12-24 19:50:43 +00:00
|
|
|
void operator_wrapper(wmOperatorType *ot, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
/* take care not to overwrite anything set in
|
|
|
|
|
* WM_operatortype_append_ptr before opfunc() is called */
|
|
|
|
|
StructRNA *srna = ot->srna;
|
|
|
|
|
*ot= *((wmOperatorType *)userdata);
|
|
|
|
|
ot->srna= srna; /* restore */
|
|
|
|
|
|
|
|
|
|
RNA_struct_blender_type_set(ot->ext.srna, ot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Can't use this because it returns a dict proxy
|
|
|
|
|
*
|
|
|
|
|
* item= PyObject_GetAttrString(py_class, "__dict__");
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
PyObject *py_class = ot->ext.data;
|
|
|
|
|
PyObject *item= ((PyTypeObject*)py_class)->tp_dict;
|
|
|
|
|
if(item) {
|
|
|
|
|
/* only call this so pyrna_deferred_register_props gives a useful error
|
|
|
|
|
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
|
|
|
|
* later */
|
|
|
|
|
RNA_def_struct_identifier(ot->srna, ot->idname);
|
|
|
|
|
|
|
|
|
|
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
|
|
|
|
|
/* failed to register operator props */
|
|
|
|
|
PyErr_Print();
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
void macro_wrapper(wmOperatorType *ot, void *userdata)
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
{
|
2009-12-30 22:14:32 +00:00
|
|
|
wmOperatorType *data = (wmOperatorType *)userdata;
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
/* only copy a couple of things, the rest is set by the macro registration */
|
|
|
|
|
ot->name = data->name;
|
|
|
|
|
ot->idname = data->idname;
|
|
|
|
|
ot->description = data->description;
|
|
|
|
|
ot->flag |= data->flag; /* append flags to the one set by registration */
|
|
|
|
|
ot->pyop_poll = data->pyop_poll;
|
|
|
|
|
ot->ui = data->ui;
|
|
|
|
|
ot->ext = data->ext;
|
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
2009-10-10 21:23:20 +00:00
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
RNA_struct_blender_type_set(ot->ext.srna, ot);
|
2009-12-24 19:50:43 +00:00
|
|
|
|
2009-10-08 07:54:20 +00:00
|
|
|
|
define operator properties in the class, similar to django fields
# Before
[
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True),
bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True),
bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
# After
path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True)
use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True)
use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True)
use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
2009-10-31 16:40:14 +00:00
|
|
|
/* Can't use this because it returns a dict proxy
|
|
|
|
|
*
|
|
|
|
|
* item= PyObject_GetAttrString(py_class, "__dict__");
|
|
|
|
|
*/
|
2009-12-30 22:14:32 +00:00
|
|
|
{
|
|
|
|
|
PyObject *py_class = ot->ext.data;
|
|
|
|
|
PyObject *item= ((PyTypeObject*)py_class)->tp_dict;
|
|
|
|
|
if(item) {
|
|
|
|
|
/* only call this so pyrna_deferred_register_props gives a useful error
|
|
|
|
|
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
|
|
|
|
|
* later */
|
|
|
|
|
RNA_def_struct_identifier(ot->srna, ot->idname);
|
2009-11-19 14:32:12 +00:00
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
|
|
|
|
|
/* failed to register operator props */
|
|
|
|
|
PyErr_Print();
|
|
|
|
|
PyErr_Clear();
|
2009-11-19 14:32:12 +00:00
|
|
|
|
2009-12-30 22:14:32 +00:00
|
|
|
}
|
python operators (in bpy_opwrapper.*)
This means you can define an operator in python that is called from C or Python - like any other operator.
Python functions for invoke and exec can be registered with an operator name.
keywords are read from the python exec() function, then used to create operator properties. The default python values are used to set the property type and defaults.
def exec(size=2.0, text="blah"): ...
is equivalent to...
prop = RNA_def_property(ot->srna, "size", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_default(prop, 2.0f);
prop = RNA_def_property(ot->srna, "size", PROP_STRING, PROP_NONE);
RNA_def_property_string_default(prop, "blah");
TODO -
* make use of events
* return OPERATOR_CANCELLED/OPERATOR_FINISHED.. etc
* add support for array args
* more testing
2008-12-27 14:52:49 +00:00
|
|
|
}
|
2009-12-30 22:14:32 +00:00
|
|
|
else {
|
2009-12-05 19:27:26 +00:00
|
|
|
PyErr_Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
wmOperatorType *ot;
|
|
|
|
|
wmOperatorTypeMacro *otmacro;
|
|
|
|
|
PyObject *macro;
|
|
|
|
|
PointerRNA ptr_otmacro;
|
2009-12-30 22:14:32 +00:00
|
|
|
StructRNA *srna;
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
char *opname;
|
2009-12-30 22:14:32 +00:00
|
|
|
const char *macroname;
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", ¯o, &opname))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (WM_operatortype_exists(opname) == NULL) {
|
|
|
|
|
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid operator id", opname);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
2009-12-30 22:14:32 +00:00
|
|
|
srna= srna_from_self(macro);
|
|
|
|
|
macroname = RNA_struct_identifier(srna);
|
2009-12-05 19:27:26 +00:00
|
|
|
|
|
|
|
|
ot = WM_operatortype_exists(macroname);
|
|
|
|
|
|
|
|
|
|
if (!ot) {
|
|
|
|
|
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
otmacro = WM_operatortype_macro_define(ot, opname);
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(NULL, &RNA_OperatorTypeMacro, otmacro, &ptr_otmacro);
|
|
|
|
|
|
|
|
|
|
return pyrna_struct_CreatePyObject(&ptr_otmacro);
|
|
|
|
|
}
|
|
|
|
|
|