Changed adduplicate() to take the dupflags as an argument. so faking the Alt Key isnt needed anymore in Blender or python.

Changed Pythons Object.Duplicate() to take keyword parms to enable duplication of spesific data.
Eg- Object.Duplicate(mesh=1) # to duplicate mesh data also.
This commit is contained in:
2006-01-02 10:40:13 +00:00
parent 362c8baac4
commit 8b0c3de7d9
9 changed files with 75 additions and 46 deletions

View File

@@ -114,7 +114,7 @@ struct rctf;
static PyObject *M_Object_New( PyObject * self, PyObject * args );
PyObject *M_Object_Get( PyObject * self, PyObject * args );
static PyObject *M_Object_GetSelected( PyObject * self );
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args );
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, PyObject *kwd);
static PyObject *M_Object_Join( PyObject * self );
/* HELPER FUNCTION FOR PARENTING */
@@ -157,13 +157,14 @@ struct PyMethodDef M_Object_methods[] = {
M_Object_Get_doc},
{"GetSelected", ( PyCFunction ) M_Object_GetSelected, METH_NOARGS,
M_Object_GetSelected_doc},
{"Duplicate", ( PyCFunction ) M_Object_Duplicate, METH_VARARGS,
{"Duplicate", ( PyCFunction ) M_Object_Duplicate, METH_VARARGS | METH_KEYWORDS,
M_Object_Duplicate_doc},
{"Join", ( PyCFunction ) M_Object_Join, METH_VARARGS,
M_Object_Join_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python BPy_Object methods declarations: */
/*****************************************************************************/
@@ -811,21 +812,43 @@ static PyObject *M_Object_GetSelected( PyObject * self )
/* Function: M_Object_Duplicate */
/* Python equivalent: Blender.Object.Duplicate */
/*****************************************************************************/
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args )
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, PyObject *kwd )
{
int *linked=1;
int dupflag= 0; /* this a flag, passed to adduplicate() and used instead of U.dupflag sp python can set what is duplicated */
if( !PyArg_ParseTuple( args, "|i", &linked ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"2 ints expected as arguments" );
if (linked) {
G.qual |= LR_ALTKEY; /* patch to make sure we get a linked dupli */
adduplicate(1);
G.qual &= ~LR_ALTKEY;
} else {
adduplicate(1);
}
/* the following variables are bools, if set true they will modify the dupflag to pass to adduplicate() */
int mesh_dupe = 0;
int surface_dupe = 0;
int curve_dupe = 0;
int text_dupe = 0;
int metaball_dupe = 0;
int armature_dupe = 0;
int lamp_dupe = 0;
int material_dupe = 0;
int texture_dupe = 0;
int ipo_dupe = 0;
static char *kwlist[] = {"mesh", "surface", "curve",
"text", "metaball", "armature", "lamp", "material", "texture", "ipo", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|iiiiiiiiii", kwlist,
&mesh_dupe, &surface_dupe, &curve_dupe, &text_dupe, &metaball_dupe,
&armature_dupe, &lamp_dupe, &material_dupe, &texture_dupe, &ipo_dupe))
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected nothing or bool keywords 'mesh', 'surface', 'curve', 'text', 'metaball', 'armature', 'lamp' 'material', 'texture' and 'ipo' as arguments" );
/* USER_DUP_ACT for actions is not supported in the UI so dont support it here */
if (mesh_dupe) dupflag |= USER_DUP_MESH;
if (surface_dupe) dupflag |= USER_DUP_SURF;
if (curve_dupe) dupflag |= USER_DUP_CURVE;
if (text_dupe) dupflag |= USER_DUP_FONT;
if (metaball_dupe) dupflag |= USER_DUP_MBALL;
if (armature_dupe) dupflag |= USER_DUP_ARM;
if (lamp_dupe) dupflag |= USER_DUP_LAMP;
if (material_dupe) dupflag |= USER_DUP_MAT;
if (texture_dupe) dupflag |= USER_DUP_TEX;
if (ipo_dupe) dupflag |= USER_DUP_IPO;
adduplicate(1, dupflag); /* Duplicate the current selection, context sensitive */
Py_RETURN_NONE;
}

View File

@@ -107,13 +107,33 @@ def GetSelected ():
"""
def Duplicate (linked=1):
def Duplicate (mesh=0, surface=0, curve=0, text=0, metaball=0, armature=0, lamp=0, material=0, texture=0, ipo=0):
"""
Duplicate selected objects on visible layers from Blenders current scene.
Duplicate selected objects on visible layers from Blenders current scene,
de-selecting the currently visible, selected objects and making a copy where all new objects are selected.
By default no data linked to the object is duplicated, use the kayword arguments to change this.
Object.GetSelected() will return the list of objects resulting from duplication.
@type linked: int
@param linked: When zero this will duplicate the object data along with the object.
@type mesh: bool
@param mesh: When non zero, mesh object data will be duplicated with the objects.
@type surface: bool
@param surface: When non zero, surface object data will be duplicated with the objects.
@type curve: bool
@param curve: When non zero, curve object data will be duplicated with the objects.
@type text: bool
@param text: When non zero, text object data will be duplicated with the objects.
@type metaball: bool
@param metaball: When non zero, metaball object data will be duplicated with the objects.
@type armature: bool
@param armature: When non zero, armature object data will be duplicated with the objects.
@type lamp: bool
@param lamp: When non zero, lamp object data will be duplicated with the objects.
@type material: bool
@param material: When non zero, materials used my the object or its object data will be duplicated with the objects.
@type texture: bool
@param texture: When non zero, texture data used by the objects materials will be duplicated with the objects.
@type ipo: bool
@param ipo: When non zero, ipo data linked to the object will be duplicated with the objects.
@return: None
I{B{Example:}}
@@ -131,15 +151,12 @@ def Duplicate (linked=1):
activeObject.sel = 1
for x in xrange(10):
Blender.Object.Duplicate(1)
Blender.Object.Duplicate() # Duplicate linked
activeObject = scn.getActiveObject()
activeObject.LocX += 1
Blender.Redraw()
@note: When duplicating, specific duplicate settings in the "Edit Methods, Duplicate with Object"
section of the preferences window will change how duplicate deals with linked data.
"""
def Join ():
"""
Joins selected objects on visible layers from Blenders current scene.