* Added functionality to the Object module for getting and setting the name of

the object.
* Added the GetSelected function. (Same as getSelected).
* Added a start for the Object.py API documentation.
* Some minor bug-fixes to the Object module.
* Added the functionality to get the IPO of the Object.
This commit is contained in:
2003-06-28 15:10:23 +00:00
parent 8155033930
commit 0ff572954e
3 changed files with 285 additions and 9 deletions

View File

@@ -70,6 +70,8 @@ struct PyMethodDef M_Object_methods[] = {
M_Object_Get_doc},
{"get", (PyCFunction)M_Object_Get, METH_VARARGS,
M_Object_Get_doc},
{"GetSelected", (PyCFunction)M_Object_GetSelected, METH_VARARGS,
M_Object_GetSelected_doc},
{"getSelected", (PyCFunction)M_Object_GetSelected, METH_VARARGS,
M_Object_GetSelected_doc},
{NULL, NULL, 0, NULL}
@@ -89,6 +91,7 @@ static PyObject *Object_getInverseMatrix (BPy_Object *self);
static PyObject *Object_getLocation (BPy_Object *self, PyObject *args);
static PyObject *Object_getMaterials (BPy_Object *self);
static PyObject *Object_getMatrix (BPy_Object *self);
static PyObject *Object_getName (BPy_Object *self);
static PyObject *Object_getParent (BPy_Object *self);
static PyObject *Object_getTracked (BPy_Object *self);
static PyObject *Object_getType (BPy_Object *self);
@@ -101,6 +104,7 @@ static PyObject *Object_setDrawType (BPy_Object *self, PyObject *args);
static PyObject *Object_setEuler (BPy_Object *self, PyObject *args);
static PyObject *Object_setLocation (BPy_Object *self, PyObject *args);
static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args);
static PyObject *Object_setName (BPy_Object *self, PyObject *args);
static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args);
/*****************************************************************************/
@@ -135,6 +139,8 @@ data.\nCurrently, this is only supported for a Mesh"},
"Returns list of materials assigned to the object"},
{"getMatrix", (PyCFunction)Object_getMatrix, METH_NOARGS,
"Returns the object matrix"},
{"getName", (PyCFunction)Object_getName, METH_NOARGS,
"Returns the name of the object"},
{"getParent", (PyCFunction)Object_getParent, METH_NOARGS,
"Returns the object's parent object"},
{"getTracked", (PyCFunction)Object_getTracked, METH_NOARGS,
@@ -173,6 +179,8 @@ triple."},
{"setMaterials", (PyCFunction)Object_setMaterials, METH_VARARGS,
"Sets materials. The argument must be a list of valid material\n\
objects."},
{"setName", (PyCFunction)Object_setName, METH_VARARGS,
"Sets the name of the object"},
{"shareFrom", (PyCFunction)Object_shareFrom, METH_VARARGS,
"Link data of self with object specified in the argument. This\n\
works only if self and the object specified are of the same type."},
@@ -368,6 +376,8 @@ PyObject *M_Object_New(PyObject *self, PyObject *args)
blen_object->object = object;
blen_object->data = NULL;
blen_object->parent = NULL;
blen_object->track = NULL;
blen_object->ipo = NULL;
return ((PyObject*)blen_object);
}
@@ -399,6 +409,8 @@ PyObject *M_Object_Get(PyObject *self, PyObject *args)
blen_object->object = object;
blen_object->parent = NULL;
blen_object->data = NULL;
blen_object->track = NULL;
blen_object->ipo = NULL;
return ((PyObject*)blen_object);
}
@@ -483,6 +495,9 @@ static PyObject *M_Object_GetSelected (PyObject *self, PyObject *args)
}
blen_object->object = base_iter->object;
blen_object->data = NULL;
blen_object->parent = NULL;
blen_object->track = NULL;
blen_object->ipo = NULL;
PyList_Append (list, (PyObject*)blen_object);
}
base_iter = base_iter->next;
@@ -533,6 +548,7 @@ static PyObject *Object_clrParent (BPy_Object *self, PyObject *args)
sort_baselist (G.scene);
}
Py_INCREF (Py_None);
return (Py_None);
}
@@ -702,6 +718,16 @@ static PyObject *Object_getMatrix (BPy_Object *self)
return (newMatrixObject (ob->obmat));
}
static PyObject *Object_getName (BPy_Object *self)
{
PyObject *attr = Py_BuildValue ("s", self->object->id.name);
if (attr) return (attr);
return (PythonReturnErrorObject (PyExc_RuntimeError,
"couldn't get the name of the Object"));
}
static PyObject *Object_getParent (BPy_Object *self)
{
PyObject *attr;
@@ -846,8 +872,8 @@ static PyObject *Object_makeParent (BPy_Object *self, PyObject *args)
BPy_Object * py_obj_child;
Object * child;
Object * parent;
int noninverse;
int fast;
int noninverse = 0;
int fast = 0;
int i;
/* Check if the arguments passed to makeParent are valid. */
@@ -1070,9 +1096,33 @@ static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args)
"setMaterials: not yet implemented"));
}
static PyObject *Object_setName (BPy_Object *self, PyObject *args)
{
char * name;
int length;
if (!PyArg_Parse (args, "s#", &name, &length))
{
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected a String as argument"));
}
if (length > 23)
{
return (PythonReturnErrorObject (PyExc_AttributeError,
"name argument may not exceed 23 characters"));
}
free (self->object->id.name);
strncpy (self->object->id.name, name, length);
Py_INCREF (Py_None);
return (Py_None);
}
static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args)
{
BPy_Object * object;
BPy_Object * object;
ID * id;
ID * oldid;
@@ -1126,6 +1176,8 @@ static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args)
"type not supported");
return (NULL);
}
Py_INCREF (Py_None);
return (Py_None);
}
@@ -1277,14 +1329,25 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
return (Object_getData (obj));
if (StringEqual (name, "ipo"))
{
printf ("This is not implemented yet.\n");
return (Py_None);
if (obj->ipo == NULL)
{
obj->ipo = Ipo_CreatePyObject (object->ipo);
}
else
{
if (Ipo_FromPyObject (obj->ipo) != object->ipo)
{
/* The ipo object has changed, so decref the original */
/* py_ipo object, and create a new one. */
Py_DECREF (obj->ipo);
obj->ipo = Ipo_CreatePyObject (object->ipo);
}
}
Py_INCREF (obj->ipo);
return (obj->ipo);
}
if (StringEqual (name, "mat"))
{
printf ("This is not implemented yet. (matrix)\n");
return (Py_None);
}
return (Object_getMatrix (obj));
if (StringEqual (name, "matrix"))
return (Object_getMatrix (obj));
if (StringEqual (name, "colbits"))
@@ -1293,6 +1356,8 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
return (Py_BuildValue ("b", object->dt));
if (StringEqual (name, "drawMode"))
return (Py_BuildValue ("b", object->dtx));
if (StringEqual (name, "name"))
return (Py_BuildValue ("s", object->id.name));
/* not an attribute, search the methods table */
return Py_FindMethod(BPy_Object_methods, (PyObject *)obj, name);
@@ -1456,6 +1521,13 @@ static int Object_setAttr (BPy_Object *obj, char *name, PyObject *value)
else
return (0);
}
if (StringEqual (name, "name"))
{
if (Object_setName (obj, value) != Py_None)
return (-1);
else
return (0);
}
printf ("Unknown variable.\n");
return (0);

View File

@@ -83,6 +83,10 @@ typedef struct {
/* points to the object that is tracking this object. This is only set */
/* when there's a valid PyObject (already created at some point). */
struct BPy_Object * track;
/* points to the ipo object. This is only set when there's a valid */
/* PyObject (already created at some point). */
PyObject * ipo;
} BPy_Object;
#endif /* EXPP_OBJECT_H */

View File

@@ -0,0 +1,200 @@
# Blender.Object module and the Object PyType object
"""
The Blender.Object submodule
This module provides access to the B{Object Data} in Blender.
Example::
import Blender
scene = Blencer.Scene.getCurrent () # get the current scene
ob = Blender.Object.New ('Camera') # make camera object
cam = Blender.Camera.New ('ortho') # make ortho camera data object
ob.link (cam) # link camera data with the object
scene.link (ob) # link the object into the scene
ob.setLocation (0.0, -5.0, 1.0) # position the object in the scene
"""
def New (type, name='type'):
"""
Creates a new Object.
@type type: string
@param type: The Object type: 'Armature', 'Camera', 'Curve', 'Lamp', 'Mesh' or 'Empty'.
@type name: string
@param name: The name of the object. By default, the name will be the same as the object type.
@rtype: Blender Object
@return: The created Object.
"""
def Get (name = None):
"""
Get the Object from Blender.
@type name: string
@param name: The name of the requested Object.
@rtype: Blender Object or a list of Blender Objects
@return: It depends on the 'name' parameter:
- (name): The Object with the given name;
- (): A list with all Objects in the current scene.
"""
def GetSelected ():
"""
Get the selected objects from Blender.
@rtype: A list of Blender Objects.
@return: A list of all selected Objects in the current scene.
"""
class Object:
"""
The Object object
=================
This object gives access to generic data from all objects in Blender.
@cvar LocX: The X location coordinate of the object.
@cvar LocY: The Y location coordinate of the object.
@cvar LocZ: The Z location coordinate of the object.
@cvar loc: The (X,Y,Z) location coordinates of the object (vector).
@cvar dLocX: The delta X location coordinate of the object.
@cvar dLocY: The delta Y location coordinate of the object.
@cvar dLocZ: The delta Z location coordinate of the object.
@cvar dloc: The delta (X,Y,Z) location coordinates of the object (vector).
@cvar RotX: The X rotation angle (in radians) of the object.
@cvar RotY: The Y rotation angle (in radians) of the object.
@cvar RotZ: The Z rotation angle (in radians) of the object.
@cvar rot: The (X,Y,Z) rotation angles (in radians) of the object (vector).
@cvar dRotX: The delta X rotation angle (in radians) of the object.
@cvar dRotY: The delta Y rotation angle (in radians) of the object.
@cvar dRotZ: The delta Z rotation angle (in radians) of the object.
@cvar drot: The delta (X,Y,Z) rotation angles (in radians) of the object (vector).
@cvar SizeX: The X size of the object.
@cvar SizeY: The Y size of the object.
@cvar SizeZ: The Z size of the object.
@cvar size: The (X,Y,Z) size of the object (vector).
@cvar dSizeX: The delta X size of the object.
@cvar dSizeY: The delta Y size of the object.
@cvar dSizeZ: The delta Z size of the object.
@cvar dsize: The delta (X,Y,Z) size of the object.
@cvar EffX: The X effector coordinate of the object. Only applies to IKA.
@cvar EffY: The Y effector coordinate of the object. Only applies to IKA.
@cvar EffZ: The Z effector coordinate of the object. Only applies to IKA.
@cvar Layer: The object layer (as a bitmask).
@cvar parent: The parent object of the object. (Read-only)
@cvar track: The object tracking this object. (Read-only)
@cvar data: The data of the object. (Read-only)
@cvar ipo: The ipo data associated with the object. (Read-only)
@cvar mat: The actual matrix of the object. (Read-only)
@cvar matrix: The actual matrix of the object. (Read-only)
@cvar colbits: The Material usage mask. A set bit #n means: the Material #n in the Object's material list is used. Otherwise, the Material #n of the Objects Data material list is displayed.
@cvar drawType: The object's drawing type used. 1 - Bounding box, 2 - wire, 3 - Solid, 4- Shaded, 5 - Textured.
@cvar drawMode: The object's drawing mode used. The value can be a sum of: 2 - axis, 4 - texspace, 8 - drawname, 16 - drawimage, 32 - drawwire.
@cvar name: The name of the object.
"""
def clrParent(mode = 0, fast = 0):
"""
Clears parent object.
@type mode: int
@type fast: int
@param mode: A mode flag. If mode flag is 2, then the object transform will be kept. Any other value, or no value at all will update the object transform.
@param fast: If the value is 0, the scene hierarchy will not be updated. Any other value, or no value at all will update the scene hierarchy.
"""
def getData():
"""
"""
def getDeformData():
"""
"""
def getDeltaLocation():
"""
"""
def getDrawMode():
"""
"""
def getDrawType():
"""
"""
def getEuler():
"""
"""
def getInverseMatrix():
"""
"""
def getLocation():
"""
"""
def getMaterials():
"""
"""
def getMatrix():
"""
"""
def getName():
"""
"""
def getParent():
"""
"""
def getTracked():
"""
"""
def getType():
"""
"""
def link(object):
"""
"""
def makeParent(objects, noninverse = 0, fast = 0):
"""
"""
def materialUsage(material_source = 'Data'):
"""
"""
def setDeltaLocation(float, float, float):
"""
"""
def setDrawMode(char):
"""
"""
def setDrawType(char):
"""
"""
def setEuler(float, float, float):
"""
"""
def setLocation(float, float, float):
"""
"""
def setMaterials(materials):
"""
"""
def setName(String):
"""
"""
def shareFrom(Object):
"""
"""