Added the function Duplicate to the object module.
Object.Duplicate(linked=1) Basicly a wrapper for adduplicate(); There was previously no easy way to copy objects in python. even the ways that do exist dont take modifiers, particles etc into account. Uses the current selection.. epydocs included also. - Cam
This commit is contained in:
@@ -114,6 +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 );
|
||||
|
||||
/* HELPER FUNCTION FOR PARENTING */
|
||||
static PyObject *internal_makeParent(Object *parent, PyObject *py_child, int partype, int noninverse, int fast, int v1, int v2, int v3);
|
||||
@@ -139,6 +140,9 @@ char M_Object_GetSelected_doc[] =
|
||||
"() - Returns a list of selected Objects in the active layer(s)\n\
|
||||
The active object is the first in the list, if visible";
|
||||
|
||||
char M_Object_Duplicate_doc[] =
|
||||
"(linked) - Duplicate all selected, visible objects in the current scene";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Object module: */
|
||||
/*****************************************************************************/
|
||||
@@ -149,6 +153,8 @@ 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,
|
||||
M_Object_Duplicate_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -794,6 +800,30 @@ static PyObject *M_Object_GetSelected( PyObject * self )
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Object_Duplicate */
|
||||
/* Python equivalent: Blender.Object.Duplicate */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args )
|
||||
{
|
||||
int *linked=1;
|
||||
|
||||
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);
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: initObject */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -106,6 +106,40 @@ def GetSelected ():
|
||||
print objects
|
||||
"""
|
||||
|
||||
|
||||
def Duplicate (linked=1):
|
||||
"""
|
||||
Duplicate selected objects on visible layers from Blenders current scene.
|
||||
Object.GetSelected() will return the list of objects resulting from duplication.
|
||||
|
||||
@type linked: int
|
||||
@param linked: When zero this will duplicate the object data allong with the object.
|
||||
@return: None
|
||||
|
||||
I{B{Example:}}
|
||||
|
||||
The example below creates duplicates the active object 10 times
|
||||
and moves each object 1.0 on the X axis::
|
||||
import Blender
|
||||
|
||||
scn = Scene.GetCurrent()
|
||||
activeObject = scn.getActiveObject()
|
||||
|
||||
# Unselect all
|
||||
for ob in Blender.Object.GetSelected():
|
||||
ob.sel = 0
|
||||
activeObject.sel = 1
|
||||
|
||||
for x in xrange(10):
|
||||
Blender.Object.Duplicate(1)
|
||||
activeObject = scn.getActiveObject()
|
||||
activeObject.LocX += 1
|
||||
Blender.Redraw()
|
||||
@note: When duplicating, spesific duplicate settings in the "Edit Methods, Duplicate with Object"
|
||||
section of the preferences window will change how duplicate deals with linked data.
|
||||
"""
|
||||
|
||||
|
||||
class Object:
|
||||
"""
|
||||
The Object object
|
||||
|
||||
Reference in New Issue
Block a user