3 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
26 * The Object module provides generic access to Objects of various types via
27 * the Python interface.
30 * Contributor(s): Michel Selten, Willian Germano, Jacques Guignot,
31 * Joseph Gilbert, Stephen Swaney, Bala Gi
33 * ***** END GPL/BL DUAL LICENSE BLOCK *****
38 /*****************************************************************************/
39 /* Python API function prototypes for the Blender module. */
40 /*****************************************************************************/
41 static PyObject *M_Object_New(PyObject *self, PyObject *args);
42 PyObject *M_Object_Get(PyObject *self, PyObject *args);
43 PyObject *M_Object_get(PyObject *self, PyObject *args);
44 static PyObject *M_Object_GetSelected (PyObject *self, PyObject *args);
45 static PyObject *M_Object_getSelected (PyObject *self, PyObject *args);
47 /*****************************************************************************/
48 /* The following string definitions are used for documentation strings. */
49 /* In Python these will be written to the console when doing a */
50 /* Blender.Object.__doc__ */
51 /*****************************************************************************/
53 "The Blender Object module\n\n\
54 This module provides access to **Object Data** in Blender.\n";
56 char M_Object_New_doc[] =
57 "(type) - Add a new object of type 'type' in the current scene";
59 char M_Object_Get_doc[] =
60 "(name) - return the object with the name 'name', returns None if not\
62 If 'name' is not specified, it returns a list of all objects in the\n\
65 char M_Object_GetSelected_doc[] =
66 "() - Returns a list of selected Objects in the active layer(s)\n\
67 The active object is the first in the list, if visible";
69 /*****************************************************************************/
70 /* Python method structure definition for Blender.Object module: */
71 /*****************************************************************************/
72 struct PyMethodDef M_Object_methods[] = {
73 {"New", (PyCFunction)M_Object_New, METH_VARARGS,
75 {"Get", (PyCFunction)M_Object_Get, METH_VARARGS,
77 {"get", (PyCFunction)M_Object_get, METH_VARARGS,
79 {"GetSelected", (PyCFunction)M_Object_GetSelected, METH_VARARGS,
80 M_Object_GetSelected_doc},
81 {"getSelected", (PyCFunction)M_Object_getSelected, METH_VARARGS,
82 M_Object_GetSelected_doc},
86 /*****************************************************************************/
87 /* Python BPy_Object methods declarations: */
88 /*****************************************************************************/
89 static PyObject *Object_buildParts (BPy_Object *self);
90 static PyObject *Object_clearIpo (BPy_Object *self);
91 static PyObject *Object_clrParent (BPy_Object *self, PyObject *args);
92 static PyObject *Object_getData (BPy_Object *self);
93 static PyObject *Object_getDeltaLocation (BPy_Object *self);
94 static PyObject *Object_getDrawMode (BPy_Object *self);
95 static PyObject *Object_getDrawType (BPy_Object *self);
96 static PyObject *Object_getEuler (BPy_Object *self);
97 static PyObject *Object_getInverseMatrix (BPy_Object *self);
98 static PyObject *Object_getIpo (BPy_Object *self);
99 static PyObject *Object_getLocation (BPy_Object *self, PyObject *args);
100 static PyObject *Object_getMaterials (BPy_Object *self);
101 static PyObject *Object_getMatrix (BPy_Object *self);
102 static PyObject *Object_getName (BPy_Object *self);
103 static PyObject *Object_getParent (BPy_Object *self);
104 static PyObject *Object_getSize (BPy_Object *self, PyObject *args);
105 static PyObject *Object_getTimeOffset (BPy_Object *self);
106 static PyObject *Object_getTracked (BPy_Object *self);
107 static PyObject *Object_getType (BPy_Object *self);
108 static PyObject *Object_getBoundBox (BPy_Object *self);
109 static PyObject *Object_makeDisplayList (BPy_Object *self);
110 static PyObject *Object_link (BPy_Object *self, PyObject *args);
111 static PyObject *Object_makeParent (BPy_Object *self, PyObject *args);
112 static PyObject *Object_materialUsage (BPy_Object *self, PyObject *args);
113 static PyObject *Object_setDeltaLocation (BPy_Object *self, PyObject *args);
114 static PyObject *Object_setDrawMode (BPy_Object *self, PyObject *args);
115 static PyObject *Object_setDrawType (BPy_Object *self, PyObject *args);
116 static PyObject *Object_setEuler (BPy_Object *self, PyObject *args);\
117 static PyObject *Object_setMatrix (BPy_Object *self, PyObject *args);
118 static PyObject *Object_setIpo (BPy_Object *self, PyObject *args);
119 static PyObject *Object_setLocation (BPy_Object *self, PyObject *args);
120 static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args);
121 static PyObject *Object_setName (BPy_Object *self, PyObject *args);
122 static PyObject *Object_setSize (BPy_Object *self, PyObject *args);
123 static PyObject *Object_setTimeOffset (BPy_Object *self, PyObject *args);
124 static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args);
126 /*****************************************************************************/
127 /* Python BPy_Object methods table: */
128 /*****************************************************************************/
129 static PyMethodDef BPy_Object_methods[] = {
130 /* name, method, flags, doc */
131 {"buildParts", (PyCFunction)Object_buildParts, METH_NOARGS,
132 "Recalcs particle system (if any) "},
133 {"getIpo", (PyCFunction)Object_getIpo, METH_NOARGS,
134 "Returns the ipo of this object (if any) "},
135 {"clrParent", (PyCFunction)Object_clrParent, METH_VARARGS,
136 "Clears parent object. Optionally specify:\n\
137 mode\n\t2: Keep object transform\nfast\n\t>0: Don't update scene \
138 hierarchy (faster)"},
139 {"getData", (PyCFunction)Object_getData, METH_NOARGS,
140 "Returns the datablock object containing the object's data, e.g. Mesh"},
141 {"getDeltaLocation", (PyCFunction)Object_getDeltaLocation, METH_NOARGS,
142 "Returns the object's delta location (x, y, z)"},
143 {"getDrawMode", (PyCFunction)Object_getDrawMode, METH_NOARGS,
144 "Returns the object draw modes"},
145 {"getDrawType", (PyCFunction)Object_getDrawType, METH_NOARGS,
146 "Returns the object draw type"},
147 {"getEuler", (PyCFunction)Object_getEuler, METH_NOARGS,
148 "Returns the object's rotation as Euler rotation vector\n\
149 (rotX, rotY, rotZ)"},
150 {"getInverseMatrix", (PyCFunction)Object_getInverseMatrix, METH_NOARGS,
151 "Returns the object's inverse matrix"},
152 {"getLocation", (PyCFunction)Object_getLocation, METH_VARARGS,
153 "Returns the object's location (x, y, z)"},
154 {"getMaterials", (PyCFunction)Object_getMaterials, METH_NOARGS,
155 "Returns list of materials assigned to the object"},
156 {"getMatrix", (PyCFunction)Object_getMatrix, METH_NOARGS,
157 "Returns the object matrix"},
158 {"getName", (PyCFunction)Object_getName, METH_NOARGS,
159 "Returns the name of the object"},
160 {"getParent", (PyCFunction)Object_getParent, METH_NOARGS,
161 "Returns the object's parent object"},
162 {"getSize", (PyCFunction)Object_getSize, METH_VARARGS,
163 "Returns the object's size (x, y, z)"},
164 {"getTimeOffset", (PyCFunction)Object_getTimeOffset, METH_NOARGS,
165 "Returns the object's time offset"},
166 {"getTracked", (PyCFunction)Object_getTracked, METH_NOARGS,
167 "Returns the object's tracked object"},
168 {"getType", (PyCFunction)Object_getType, METH_NOARGS,
169 "Returns type of string of Object"},
170 {"getBoundBox", (PyCFunction)Object_getBoundBox, METH_NOARGS,
171 "Returns the object's bounding box"},
172 {"makeDisplayList", (PyCFunction)Object_makeDisplayList, METH_NOARGS,
173 "Update this object's Display List. Some changes like turning \n\
174 'SubSurf' on for a mesh need this method (followed by a Redraw) to \n\
175 show the changes on the 3d window."},
176 {"link", (PyCFunction)Object_link, METH_VARARGS,
177 "Links Object with data provided in the argument. The data must \n\
178 match the Object's type, so you cannot link a Lamp to a Mesh type object."},
179 {"makeParent", (PyCFunction)Object_makeParent, METH_VARARGS,
180 "Makes the object the parent of the objects provided in the \n\
181 argument which must be a list of valid Objects. Optional extra arguments:\n\
182 mode:\n\t0: make parent with inverse\n\t1: without inverse\n\
183 fase:\n\t0: update scene hierarchy automatically\n\t\
184 don't update scene hierarchy (faster). In this case, you must\n\t\
185 explicitely update the Scene hierarchy."},
186 {"materialUsage", (PyCFunction)Object_materialUsage, METH_VARARGS,
187 "Determines the way the material is used and returns status.\n\
188 Possible arguments (provide as strings):\n\
189 \tData: Materials assigned to the object's data are shown. (default)\n\
190 \tObject: Materials assigned to the object are shown."},
191 {"setDeltaLocation", (PyCFunction)Object_setDeltaLocation, METH_VARARGS,
192 "Sets the object's delta location which must be a vector triple."},
193 {"setDrawMode", (PyCFunction)Object_setDrawMode, METH_VARARGS,
194 "Sets the object's drawing mode. The argument can be a sum of:\n\
195 2: axis\n4: texspace\n8: drawname\n16: drawimage\n32: drawwire"},
196 {"setDrawType", (PyCFunction)Object_setDrawType, METH_VARARGS,
197 "Sets the object's drawing type. The argument must be one of:\n\
198 1: Bounding box\n2: Wire\n3: Solid\n4: Shaded\n5: Textured"},
199 {"setEuler", (PyCFunction)Object_setEuler, METH_VARARGS,
200 "Set the object's rotation according to the specified Euler\n\
201 angles. The argument must be a vector triple"},
202 {"setMatrix", (PyCFunction)Object_setMatrix, METH_VARARGS,
203 "Set and apply a new matrix for the object"},
204 {"setLocation", (PyCFunction)Object_setLocation, METH_VARARGS,
205 "Set the object's location. The first argument must be a vector\n\
207 {"setMaterials", (PyCFunction)Object_setMaterials, METH_VARARGS,
208 "Sets materials. The argument must be a list of valid material\n\
210 {"setName", (PyCFunction)Object_setName, METH_VARARGS,
211 "Sets the name of the object"},
212 {"setSize", (PyCFunction)Object_setSize, METH_VARARGS,
213 "Set the object's size. The first argument must be a vector\n\
215 {"setTimeOffset", (PyCFunction)Object_setTimeOffset, METH_VARARGS,
216 "Set the object's time offset."},
217 {"shareFrom", (PyCFunction)Object_shareFrom, METH_VARARGS,
218 "Link data of self with object specified in the argument. This\n\
219 works only if self and the object specified are of the same type."},
220 {"setIpo", (PyCFunction)Object_setIpo, METH_VARARGS,
221 "(Blender Ipo) - Sets the object's ipo"},
222 {"clearIpo", (PyCFunction)Object_clearIpo, METH_NOARGS,
223 "() - Unlink ipo from this object"},
227 /*****************************************************************************/
228 /* PythonTypeObject callback function prototypes */
229 /*****************************************************************************/
230 static void Object_dealloc (BPy_Object *obj);
231 static PyObject* Object_getAttr (BPy_Object *obj, char *name);
232 static int Object_setAttr (BPy_Object *obj, char *name, PyObject *v);
233 static PyObject* Object_repr (BPy_Object *obj);
234 static int Object_compare (BPy_Object *a, BPy_Object *b);
236 /*****************************************************************************/
237 /* Python TypeObject structure definition. */
238 /*****************************************************************************/
239 PyTypeObject Object_Type =
241 PyObject_HEAD_INIT(NULL)
243 "Blender Object", /* tp_name */
244 sizeof (BPy_Object), /* tp_basicsize */
247 (destructor)Object_dealloc, /* tp_dealloc */
249 (getattrfunc)Object_getAttr, /* tp_getattr */
250 (setattrfunc)Object_setAttr, /* tp_setattr */
251 (cmpfunc)Object_compare, /* tp_compare */
252 (reprfunc)Object_repr, /* tp_repr */
253 0, /* tp_as_number */
254 0, /* tp_as_sequence */
255 0, /* tp_as_mapping */
260 BPy_Object_methods, /* tp_methods */
264 /*****************************************************************************/
265 /* Function: M_Object_New */
266 /* Python equivalent: Blender.Object.New */
267 /*****************************************************************************/
268 PyObject *M_Object_New(PyObject *self, PyObject *args)
270 struct Object * object;
271 BPy_Object * blen_object;
276 if (!PyArg_ParseTuple(args, "s|s", &str_type, &name))
278 PythonReturnErrorObject (PyExc_TypeError, "string expected as argument");
282 if (strcmp (str_type, "Armature") == 0) type = OB_ARMATURE;
283 else if (strcmp (str_type, "Camera") == 0) type = OB_CAMERA;
284 else if (strcmp (str_type, "Curve") == 0) type = OB_CURVE;
285 /* else if (strcmp (str_type, "Text") == 0) type = OB_FONT; */
286 /* else if (strcmp (str_type, "Ika") == 0) type = OB_IKA; */
287 else if (strcmp (str_type, "Lamp") == 0) type = OB_LAMP;
288 else if (strcmp (str_type, "Lattice") == 0) type = OB_LATTICE;
289 /* else if (strcmp (str_type, "Mball") == 0) type = OB_MBALL; */
290 else if (strcmp (str_type, "Mesh") == 0) type = OB_MESH;
291 else if (strcmp (str_type, "Surf") == 0) type = OB_SURF;
292 /* else if (strcmp (str_type, "Wave") == 0) type = OB_WAVE; */
293 else if (strcmp (str_type, "Empty") == 0) type = OB_EMPTY;
296 return (PythonReturnErrorObject (PyExc_AttributeError,
297 "Unknown type specified"));
300 /* Create a new object. */
303 /* No name is specified, set the name to the type of the object. */
306 object = alloc_libblock (&(G.main->object), ID_OB, name);
314 QuatOne(object->quat);
315 QuatOne(object->dquat);
317 object->col[3]= 1.0; // alpha
319 object->size[0] = object->size[1] = object->size[2] = 1.0;
320 object->loc[0] = object->loc[1] = object->loc[2] = 0.0;
321 Mat4One(object->parentinv);
322 Mat4One(object->obmat);
323 object->dt = OB_SHADED; // drawtype
325 if (U.flag & USER_MAT_ON_OB)
327 object->colbits = -1;
329 switch (object->type)
331 case OB_CAMERA: /* fall through. */
333 object->trackflag = OB_NEGZ;
334 object->upflag = OB_POSY;
337 object->trackflag = OB_POSY;
338 object->upflag = OB_POSZ;
340 object->ipoflag = OB_OFFS_OB + OB_OFFS_PARENT;
342 /* duplivert settings */
346 object->dupend = 100;
348 /* Gameengine defaults*/
350 object->inertia = 1.0;
351 object->formfactor = 0.4;
352 object->damping = 0.04;
353 object->rdamping = 0.1;
354 object->anisotropicFriction[0] = 1.0;
355 object->anisotropicFriction[1] = 1.0;
356 object->anisotropicFriction[2] = 1.0;
357 object->gameflag = OB_PROP;
359 object->lay = 1; // Layer, by default visible
364 /* Create a Python object from it. */
365 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
366 blen_object->object = object;
368 return ((PyObject*)blen_object);
371 /*****************************************************************************/
372 /* Function: M_Object_Get */
373 /* Python equivalent: Blender.Object.Get */
374 /*****************************************************************************/
375 PyObject *M_Object_Get(PyObject *self, PyObject *args)
377 struct Object * object;
378 BPy_Object * blen_object;
381 PyArg_ParseTuple(args, "|s", &name);
385 object = GetObjectByName (name);
389 /* No object exists with the name specified in the argument name. */
390 return (PythonReturnErrorObject (PyExc_AttributeError,
391 "Unknown object specified."));
393 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
394 blen_object->object = object;
396 return ((PyObject*)blen_object);
400 /* No argument has been given. Return a list of all objects. */
405 obj_list = PyList_New (BLI_countlist (&(G.main->object)));
407 if (obj_list == NULL)
409 return (PythonReturnErrorObject (PyExc_SystemError,
410 "List creation failed."));
413 link = G.main->object.first;
417 object = (Object*)link;
418 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
419 blen_object->object = object;
421 PyList_SetItem (obj_list, index, (PyObject*)blen_object);
429 /*****************************************************************************/
430 /* Function: M_Object_get */
431 /* Python equivalent: Blender.Object.get */
432 /*****************************************************************************/
433 PyObject *M_Object_get(PyObject *self, PyObject *args)
435 PyErr_Warn (PyExc_DeprecationWarning,
436 "The Object.get() function will be removed in Blender 2.29\n" \
437 "Please update the script to use Object.Get");
438 return (M_Object_Get (self, args));
441 /*****************************************************************************/
442 /* Function: M_Object_GetSelected */
443 /* Python equivalent: Blender.Object.getSelected */
444 /*****************************************************************************/
445 static PyObject *M_Object_GetSelected (PyObject *self, PyObject *args)
447 BPy_Object * blen_object;
453 // No 3d view has been initialized yet, simply return None
457 list = PyList_New (0);
458 if ((G.scene->basact) &&
459 ((G.scene->basact->flag & SELECT) &&
460 (G.scene->basact->lay & G.vd->lay)))
462 /* Active object is first in the list. */
463 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
464 if (blen_object == NULL)
470 blen_object->object = G.scene->basact->object;
471 PyList_Append (list, (PyObject*)blen_object);
474 base_iter = G.scene->base.first;
477 if (((base_iter->flag & SELECT) &&
478 (base_iter->lay & G.vd->lay)) &&
479 (base_iter != G.scene->basact))
481 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
482 if (blen_object == NULL)
488 blen_object->object = base_iter->object;
489 PyList_Append (list, (PyObject*)blen_object);
491 base_iter = base_iter->next;
496 /*****************************************************************************/
497 /* Function: M_Object_getSelected */
498 /* Python equivalent: Blender.Object.getSelected */
499 /*****************************************************************************/
500 static PyObject *M_Object_getSelected (PyObject *self, PyObject *args)
502 PyErr_Warn (PyExc_DeprecationWarning,
503 "The Object.getSelected() function will be removed in "\
505 "Please update the script to use Object.GetSelected");
506 return (M_Object_GetSelected (self, args));
509 /*****************************************************************************/
510 /* Function: initObject */
511 /*****************************************************************************/
512 PyObject *Object_Init (void)
516 Object_Type.ob_type = &PyType_Type;
518 module = Py_InitModule3("Blender.Object", M_Object_methods, M_Object_doc);
523 /*****************************************************************************/
524 /* Python BPy_Object methods: */
525 /*****************************************************************************/
527 static PyObject *Object_buildParts (BPy_Object *self)
529 void build_particle_system(Object *ob);
530 struct Object *obj = self->object;
532 build_particle_system(obj);
538 static PyObject *Object_clearIpo(BPy_Object *self)
540 Object *ob = self->object;
541 Ipo *ipo = (Ipo *)ob->ipo;
545 if (id->us > 0) id->us--;
552 Py_INCREF (Py_False); /* no ipo found */
556 static PyObject *Object_clrParent (BPy_Object *self, PyObject *args)
561 if (!PyArg_ParseTuple (args, "|ii", &mode, &fast))
563 return (PythonReturnErrorObject (PyExc_AttributeError,
564 "expected one or two integers as arguments"));
567 /* Remove the link only, the object is still in the scene. */
568 self->object->parent = NULL;
573 apply_obmat (self->object);
578 sort_baselist (G.scene);
585 /* adds object data to a Blender object, if object->data = NULL */
586 int EXPP_add_obdata(struct Object *object)
588 if (object->data != NULL) return -1;
593 /* TODO: Do we need to add something to G? (see the OB_LAMP case) */
594 object->data = add_armature();
597 /* TODO: Do we need to add something to G? (see the OB_LAMP case) */
598 object->data = add_camera();
601 object->data = add_curve(OB_CURVE);
605 object->data = add_lamp();
609 object->data = add_mesh();
613 object->data = (void *)add_lattice();
614 object->dt = OB_WIRE;
617 /* TODO the following types will be supported later
619 object->data = add_curve(OB_SURF);
623 object->data = add_curve(OB_FONT);
626 object->data = add_mball();
629 object->data = add_ika();
630 object->dt = OB_WIRE;
633 object->data = add_wave();
640 if (!object->data) return -1;
645 static PyObject *Object_getData (BPy_Object *self)
647 PyObject * data_object;
648 Object * object = self->object;
650 /* if there's no obdata, try to create it */
651 if (object->data == NULL)
653 if (EXPP_add_obdata(object) != 0)
654 { /* couldn't create obdata */
662 switch (object->type)
665 data_object = Armature_CreatePyObject (object->data);
668 data_object = Camera_CreatePyObject (object->data);
671 data_object = Curve_CreatePyObject (object->data);
674 data_object = Image_CreatePyObject (object->data);
677 data_object = Ipo_CreatePyObject (object->data);
680 data_object = Lamp_CreatePyObject (object->data);
683 data_object = Lattice_CreatePyObject (object->data);
688 data_object = NMesh_CreatePyObject (object->data, object);
691 data_object = Object_CreatePyObject (object->data);
696 data_object = Text_CreatePyObject (object->data);
703 if (data_object == NULL)
710 return (data_object);
714 static PyObject *Object_getDeltaLocation (BPy_Object *self)
716 PyObject *attr = Py_BuildValue ("fff",
717 self->object->dloc[0],
718 self->object->dloc[1],
719 self->object->dloc[2]);
721 if (attr) return (attr);
723 return (PythonReturnErrorObject (PyExc_RuntimeError,
724 "couldn't get Object.dloc attributes"));
727 static PyObject *Object_getDrawMode (BPy_Object *self)
729 PyObject *attr = Py_BuildValue ("b", self->object->dtx);
731 if (attr) return (attr);
733 return (PythonReturnErrorObject (PyExc_RuntimeError,
734 "couldn't get Object.drawMode attribute"));
737 static PyObject *Object_getDrawType (BPy_Object *self)
739 PyObject *attr = Py_BuildValue ("b", self->object->dt);
741 if (attr) return (attr);
743 return (PythonReturnErrorObject (PyExc_RuntimeError,
744 "couldn't get Object.drawType attribute"));
747 static PyObject *Object_getEuler (BPy_Object *self)
751 eul = (EulerObject*)newEulerObject(NULL);
752 eul->eul[0] = self->object->rot[0];
753 eul->eul[1] = self->object->rot[1];
754 eul->eul[2] = self->object->rot[2];
756 return (PyObject*)eul;
760 static PyObject *Object_getInverseMatrix (BPy_Object *self)
762 MatrixObject *inverse = (MatrixObject *)newMatrixObject(NULL, 4, 4);
764 Mat4Invert (*inverse->matrix, self->object->obmat);
766 return ((PyObject *)inverse);
770 static PyObject *Object_getIpo(BPy_Object *self)
772 struct Ipo *ipo = self->object->ipo;
780 return Ipo_CreatePyObject (ipo);
783 static PyObject *Object_getLocation (BPy_Object *self, PyObject *args)
785 PyObject *attr = Py_BuildValue ("fff",
786 self->object->loc[0],
787 self->object->loc[1],
788 self->object->loc[2]);
790 if (attr) return (attr);
792 return (PythonReturnErrorObject (PyExc_RuntimeError,
793 "couldn't get Object.loc attributes"));
796 static PyObject *Object_getMaterials (BPy_Object *self)
798 return (EXPP_PyList_fromMaterialList (self->object->mat,
799 self->object->totcol));
802 static PyObject *Object_getMatrix (BPy_Object *self)
808 return (PyObject*)newMatrixObject((float*)ob->obmat, 4, 4);
811 static PyObject *Object_getName (BPy_Object *self)
813 PyObject *attr = Py_BuildValue ("s", self->object->id.name+2);
815 if (attr) return (attr);
817 return (PythonReturnErrorObject (PyExc_RuntimeError,
818 "couldn't get the name of the Object"));
821 static PyObject *Object_getParent (BPy_Object *self)
825 if (self->object->parent == NULL)
826 return EXPP_incr_ret (Py_None);
828 attr = Object_CreatePyObject (self->object->parent);
835 return (PythonReturnErrorObject (PyExc_RuntimeError,
836 "couldn't get Object.parent attribute"));
839 static PyObject *Object_getSize (BPy_Object *self, PyObject *args)
841 PyObject *attr = Py_BuildValue ("fff",
842 self->object->size[0],
843 self->object->size[1],
844 self->object->size[2]);
846 if (attr) return (attr);
848 return (PythonReturnErrorObject (PyExc_RuntimeError,
849 "couldn't get Object.size attributes"));
852 static PyObject *Object_getTimeOffset (BPy_Object *self)
854 PyObject *attr = Py_BuildValue ("f", self->object->sf);
856 if (attr) return (attr);
858 return (PythonReturnErrorObject (PyExc_RuntimeError,
859 "couldn't get Object.sf attributes"));
863 static PyObject *Object_getTracked (BPy_Object *self)
867 if (self->object->track == NULL)
868 return EXPP_incr_ret (Py_None);
870 attr = Object_CreatePyObject (self->object->track);
877 return (PythonReturnErrorObject (PyExc_RuntimeError,
878 "couldn't get Object.track attribute"));
881 static PyObject *Object_getType (BPy_Object *self)
883 switch (self->object->type)
885 case OB_ARMATURE: return (Py_BuildValue ("s", "Armature"));
886 case OB_CAMERA: return (Py_BuildValue ("s", "Camera"));
887 case OB_CURVE: return (Py_BuildValue ("s", "Curve"));
888 case OB_EMPTY: return (Py_BuildValue ("s", "Empty"));
889 case OB_FONT: return (Py_BuildValue ("s", "Text"));
890 case OB_IKA: return (Py_BuildValue ("s", "Ika"));
891 case OB_LAMP: return (Py_BuildValue ("s", "Lamp"));
892 case OB_LATTICE: return (Py_BuildValue ("s", "Lattice"));
893 case OB_MBALL: return (Py_BuildValue ("s", "MBall"));
894 case OB_MESH: return (Py_BuildValue ("s", "Mesh"));
895 case OB_SURF: return (Py_BuildValue ("s", "Surf"));
896 case OB_WAVE: return (Py_BuildValue ("s", "Wave"));
897 default: return (Py_BuildValue ("s", "unknown"));
901 static PyObject *Object_getBoundBox (BPy_Object *self)
905 PyObject *vector, *bbox;
907 if (!self->object->data)
908 return EXPP_ReturnPyObjError (PyExc_AttributeError,
909 "This object isn't linked to any object data (mesh, curve, etc) yet");
911 if (!self->object->bb) {
914 switch (self->object->type) {
916 me = self->object->data;
917 if (!me->bb) tex_space_mesh(me);
918 vec = (float *)me->bb->vec;
923 curve = self->object->data;
924 if (!curve->bb) tex_space_curve(curve);
925 vec = (float *)curve->bb->vec;
932 else vec = (float *)self->object->bb->vec;
935 return EXPP_ReturnPyObjError (PyExc_RuntimeError,
936 "couldn't retrieve bounding box data");
938 bbox = PyList_New(8);
941 return EXPP_ReturnPyObjError (PyExc_MemoryError,
942 "couldn't create pylist");
944 for (i = 0; i < 8; i++) {
945 vector = newVectorObject(vec, 3);
946 PyList_SET_ITEM(bbox, i, vector);
953 static PyObject *Object_makeDisplayList (BPy_Object *self)
955 Object *ob = self->object;
957 if (ob->type == OB_FONT) text_to_curve(ob, 0);
965 static PyObject *Object_link (BPy_Object *self, PyObject *args)
973 if (!PyArg_ParseTuple (args, "O", &py_data))
975 return (PythonReturnErrorObject (PyExc_AttributeError,
976 "expected an object as argument"));
978 if (Camera_CheckPyObject (py_data))
979 data = (void *)Camera_FromPyObject (py_data);
980 if (Lamp_CheckPyObject (py_data))
981 data = (void *)Lamp_FromPyObject (py_data);
982 if (Curve_CheckPyObject (py_data))
983 data = (void *)Curve_FromPyObject (py_data);
984 if (NMesh_CheckPyObject (py_data))
985 data = (void *)Mesh_FromPyObject (py_data, self->object);
986 if (Lattice_CheckPyObject (py_data))
987 data = (void *)Lattice_FromPyObject (py_data);
989 /* have we set data to something good? */
992 return (PythonReturnErrorObject (PyExc_AttributeError,
993 "link argument type is not supported "));
996 oldid = (ID*) self->object->data;
998 obj_id = MAKE_ID2 (id->name[0], id->name[1]);
1003 if (self->object->type != OB_CAMERA)
1005 return (PythonReturnErrorObject (PyExc_AttributeError,
1006 "The 'link' object is incompatible with the base object"));
1010 if (self->object->type != OB_LAMP)
1012 return (PythonReturnErrorObject (PyExc_AttributeError,
1013 "The 'link' object is incompatible with the base object"));
1017 if (self->object->type != OB_MESH)
1019 return (PythonReturnErrorObject (PyExc_AttributeError,
1020 "The 'link' object is incompatible with the base object"));
1024 if (self->object->type != OB_CURVE)
1026 return (PythonReturnErrorObject (PyExc_AttributeError,
1027 "The 'link' object is incompatible with the base object"));
1031 if (self->object->type != OB_LATTICE)
1033 return (PythonReturnErrorObject (PyExc_AttributeError,
1034 "The 'link' object is incompatible with the base object"));
1038 return (PythonReturnErrorObject (PyExc_AttributeError,
1039 "Linking this object type is not supported"));
1041 self->object->data = data;
1043 if ( self->object->type == OB_MESH)
1045 self->object->totcol = 0;
1046 EXPP_synchronizeMaterialLists(self->object, id);
1058 return (PythonReturnErrorObject (PyExc_RuntimeError,
1059 "old object reference count below 0"));
1062 return EXPP_incr_ret (Py_None);
1065 static PyObject *Object_makeParent (BPy_Object *self, PyObject *args)
1068 PyObject * py_child;
1069 //BPy_Object * py_obj_child; unused
1076 /* Check if the arguments passed to makeParent are valid. */
1077 if (!PyArg_ParseTuple (args, "O|ii", &list, &noninverse, &fast))
1079 return (PythonReturnErrorObject (PyExc_AttributeError,
1080 "expected a list of objects and one or two integers as arguments"));
1082 if (!PySequence_Check (list))
1084 return (PythonReturnErrorObject (PyExc_TypeError,
1085 "expected a list of objects"));
1088 /* Check if the PyObject passed in list is a Blender object. */
1089 for (i=0 ; i<PySequence_Length (list) ; i++)
1092 py_child = PySequence_GetItem (list, i);
1093 if (Object_CheckPyObject (py_child))
1094 child = (Object*) Object_FromPyObject (py_child);
1098 return (PythonReturnErrorObject (PyExc_TypeError,
1099 "Object Type expected"));
1102 parent = (Object*)self->object;
1103 if (test_parent_loop (parent, child))
1105 return (PythonReturnErrorObject (PyExc_RuntimeError,
1106 "parenting loop detected - parenting failed"));
1108 child->partype = PAROBJECT;
1109 child->parent = parent;
1110 //py_obj_child = (BPy_Object *) py_child;
1111 if (noninverse == 1)
1113 /* Parent inverse = unity */
1114 child->loc[0] = 0.0;
1115 child->loc[1] = 0.0;
1116 child->loc[2] = 0.0;
1120 what_does_parent (child);
1121 Mat4Invert (child->parentinv, parent->obmat);
1126 sort_baselist (G.scene);
1129 // We don't need the child object anymore.
1130 //Py_DECREF ((PyObject *) child);
1132 return EXPP_incr_ret (Py_None);
1135 static PyObject *Object_materialUsage (BPy_Object *self, PyObject *args)
1137 return (PythonReturnErrorObject (PyExc_NotImplementedError,
1138 "materialUsage: not yet implemented"));
1141 static PyObject *Object_setDeltaLocation (BPy_Object *self, PyObject *args)
1148 if (PyObject_Length (args) == 3)
1149 status = PyArg_ParseTuple (args, "fff", &dloc1, &dloc2, &dloc3);
1151 status = PyArg_ParseTuple (args, "(fff)", &dloc1, &dloc2, &dloc3);
1154 return EXPP_ReturnPyObjError (PyExc_AttributeError,
1155 "expected list argument of 3 floats");
1157 self->object->dloc[0] = dloc1;
1158 self->object->dloc[1] = dloc2;
1159 self->object->dloc[2] = dloc3;
1161 Py_INCREF (Py_None);
1165 static PyObject *Object_setDrawMode (BPy_Object *self, PyObject *args)
1169 if (!PyArg_ParseTuple (args, "b", &dtx))
1171 return (PythonReturnErrorObject (PyExc_AttributeError,
1172 "expected an integer as argument"));
1174 self->object->dtx = dtx;
1176 Py_INCREF (Py_None);
1180 static PyObject *Object_setDrawType (BPy_Object *self, PyObject *args)
1184 if (!PyArg_ParseTuple (args, "b", &dt))
1186 return (PythonReturnErrorObject (PyExc_AttributeError,
1187 "expected an integer as argument"));
1189 self->object->dt = dt;
1191 Py_INCREF (Py_None);
1195 static PyObject *Object_setEuler (BPy_Object *self, PyObject *args)
1203 if (!PyArg_ParseTuple (args, "O", &ob))
1204 return (PythonReturnErrorObject (PyExc_AttributeError,
1205 "unknown type passed to function (setEuler)"));
1207 //test to see if it's a list or a euler
1208 if(PyList_Check(ob)){
1209 if (PyObject_Length (args) == 3)
1210 status = PyArg_ParseTuple (args, "fff", &rot1, &rot2, &rot3);
1212 status = PyArg_ParseTuple (args, "(fff)", &rot1, &rot2, &rot3);
1214 return EXPP_ReturnPyObjError (PyExc_AttributeError,
1215 "expected list argument of 3 floats");
1216 }else if(EulerObject_Check(ob)){
1217 rot1 = ((EulerObject*)ob)->eul[0];
1218 rot2 = ((EulerObject*)ob)->eul[1];
1219 rot3 = ((EulerObject*)ob)->eul[2];
1222 return (PythonReturnErrorObject (PyExc_AttributeError,
1223 "expected list of floats or euler"));
1226 self->object->rot[0] = rot1;
1227 self->object->rot[1] = rot2;
1228 self->object->rot[2] = rot3;
1230 Py_INCREF (Py_None);
1234 static PyObject *Object_setMatrix (BPy_Object *self, PyObject *args)
1239 if (!PyArg_ParseTuple(args, "O!", &matrix_Type, &mat))
1240 return EXPP_ReturnPyObjError
1241 (PyExc_TypeError, "expected matrix object as argument");
1243 for(x = 0; x < 4; x++){
1244 for(y = 0; y < 4; y++){
1245 self->object->obmat[x][y] = mat->matrix[x][y];
1248 apply_obmat(self->object);
1250 Py_INCREF (Py_None);
1254 static PyObject *Object_setIpo(BPy_Object *self, PyObject *args)
1256 PyObject *pyipo = 0;
1260 if (!PyArg_ParseTuple(args, "O!", &Ipo_Type, &pyipo))
1261 return EXPP_ReturnPyObjError (PyExc_TypeError, "expected Ipo as argument");
1263 ipo = Ipo_FromPyObject(pyipo);
1265 if (!ipo) return EXPP_ReturnPyObjError (PyExc_RuntimeError, "null ipo!");
1267 if (ipo->blocktype != ID_OB)
1268 return EXPP_ReturnPyObjError (PyExc_TypeError,
1269 "this ipo is not an object ipo");
1271 oldipo = self->object->ipo;
1273 ID *id = &oldipo->id;
1274 if (id->us > 0) id->us--;
1277 ((ID *)&ipo->id)->us++;
1279 self->object->ipo = ipo;
1285 static PyObject *Object_setLocation (BPy_Object *self, PyObject *args)
1292 if (PyObject_Length (args) == 3)
1293 status = PyArg_ParseTuple (args, "fff", &loc1, &loc2, &loc3);
1295 status = PyArg_ParseTuple (args, "(fff)", &loc1, &loc2, &loc3);
1298 return EXPP_ReturnPyObjError (PyExc_AttributeError,
1299 "expected list argument of 3 floats");
1301 self->object->loc[0] = loc1;
1302 self->object->loc[1] = loc2;
1303 self->object->loc[2] = loc3;
1305 Py_INCREF (Py_None);
1309 static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args)
1314 Material ** matlist;
1316 if (!PyArg_ParseTuple (args, "O", &list))
1318 return (PythonReturnErrorObject (PyExc_AttributeError,
1319 "expected a list of materials as argument"));
1322 len = PySequence_Length (list);
1325 matlist = EXPP_newMaterialList_fromPyList (list);
1328 return (PythonReturnErrorObject (PyExc_AttributeError,
1329 "material list must be a list of valid materials!"));
1331 if ((len < 0) || (len > MAXMAT))
1333 return (PythonReturnErrorObject (PyExc_RuntimeError,
1334 "illegal material index!"));
1337 if (self->object->mat)
1339 EXPP_releaseMaterialList (self->object->mat, len);
1341 /* Increase the user count on all materials */
1342 for (i=0 ; i<len ; i++)
1344 id_us_plus ((ID *) matlist[i]);
1346 self->object->mat = matlist;
1347 self->object->totcol = len;
1348 self->object->actcol = -1;
1350 switch (self->object->type)
1352 case OB_CURVE: /* fall through */
1353 case OB_FONT: /* fall through */
1354 case OB_MESH: /* fall through */
1355 case OB_MBALL: /* fall through */
1357 EXPP_synchronizeMaterialLists (self->object,
1358 self->object->data);
1364 return EXPP_incr_ret (Py_None);
1367 static PyObject *Object_setName (BPy_Object *self, PyObject *args)
1372 if (!PyArg_ParseTuple (args, "s", &name))
1374 return (PythonReturnErrorObject (PyExc_AttributeError,
1375 "expected a String as argument"));
1378 PyOS_snprintf(buf, sizeof(buf), "%s", name);
1380 rename_id(&self->object->id, buf);
1382 Py_INCREF (Py_None);
1386 static PyObject *Object_setSize (BPy_Object *self, PyObject *args)
1393 if (PyObject_Length (args) == 3)
1394 status = PyArg_ParseTuple (args, "fff", &sizex, &sizey, &sizez);
1396 status = PyArg_ParseTuple (args, "(fff)", &sizex, &sizey, &sizez);
1399 return EXPP_ReturnPyObjError (PyExc_AttributeError,
1400 "expected list argument of 3 floats");
1402 self->object->size[0] = sizex;
1403 self->object->size[1] = sizey;
1404 self->object->size[2] = sizez;
1406 Py_INCREF (Py_None);
1410 static PyObject *Object_setTimeOffset (BPy_Object *self, PyObject *args)
1412 float newTimeOffset;
1414 if (!PyArg_ParseTuple (args, "f", &newTimeOffset))
1416 return (PythonReturnErrorObject (PyExc_AttributeError,
1417 "expected a float as argument"));
1420 self->object->sf=newTimeOffset;
1422 Py_INCREF (Py_None);
1426 static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args)
1428 BPy_Object * object;
1432 if (!PyArg_ParseTuple (args, "O", &object))
1434 PythonReturnErrorObject (PyExc_AttributeError,
1435 "expected an object argument");
1438 if (!Object_CheckPyObject ((PyObject*)object))
1440 PythonReturnErrorObject (PyExc_TypeError,
1441 "argument 1 is not of type 'Object'");
1445 if (self->object->type != object->object->type)
1447 PythonReturnErrorObject (PyExc_TypeError,
1448 "objects are not of same data type");
1451 switch (self->object->type)
1455 case OB_CAMERA: /* we can probably add the other types, too */
1460 oldid = (ID*) self->object->data;
1461 id = (ID*) object->object->data;
1462 self->object->data = object->object->data;
1464 if ( self->object->type == OB_MESH && id ){
1465 self->object->totcol = 0;
1466 EXPP_synchronizeMaterialLists(self->object, id);
1478 return (PythonReturnErrorObject (PyExc_RuntimeError,
1479 "old object reference count below 0"));
1482 Py_INCREF (Py_None);
1485 PythonReturnErrorObject (PyExc_TypeError,
1486 "type not supported");
1490 Py_INCREF (Py_None);
1494 /*****************************************************************************/
1495 /* Function: Object_CreatePyObject */
1496 /* Description: This function will create a new BlenObject from an existing */
1497 /* Object structure. */
1498 /*****************************************************************************/
1499 PyObject* Object_CreatePyObject (struct Object *obj)
1501 BPy_Object * blen_object;
1503 blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
1505 if (blen_object == NULL)
1509 blen_object->object = obj;
1510 return ((PyObject*)blen_object);
1513 /*****************************************************************************/
1514 /* Function: Object_CheckPyObject */
1515 /* Description: This function returns true when the given PyObject is of the */
1516 /* type Object. Otherwise it will return false. */
1517 /*****************************************************************************/
1518 int Object_CheckPyObject (PyObject *py_obj)
1520 return (py_obj->ob_type == &Object_Type);
1523 /*****************************************************************************/
1524 /* Function: Object_FromPyObject */
1525 /* Description: This function returns the Blender object from the given */
1527 /*****************************************************************************/
1528 struct Object* Object_FromPyObject (PyObject *py_obj)
1530 BPy_Object * blen_obj;
1532 blen_obj = (BPy_Object*)py_obj;
1533 return (blen_obj->object);
1536 /*****************************************************************************/
1537 /* Description: Returns the object with the name specified by the argument */
1538 /* name. Note that the calling function has to remove the first */
1539 /* two characters of the object name. These two characters */
1540 /* specify the type of the object (OB, ME, WO, ...) */
1541 /* The function will return NULL when no object with the given */
1542 /* name is found. */
1543 /*****************************************************************************/
1544 Object * GetObjectByName (char * name)
1548 obj_iter = G.main->object.first;
1551 if (StringEqual (name, GetIdName (&(obj_iter->id))))
1555 obj_iter = obj_iter->id.next;
1558 /* There is no object with the given name */
1562 /*****************************************************************************/
1563 /* Function: Object_dealloc */
1564 /* Description: This is a callback function for the BlenObject type. It is */
1565 /* the destructor function. */
1566 /*****************************************************************************/
1567 static void Object_dealloc (BPy_Object *obj)
1572 /*****************************************************************************/
1573 /* Function: Object_getAttr */
1574 /* Description: This is a callback function for the BlenObject type. It is */
1575 /* the function that retrieves any value from Blender and */
1576 /* passes it to Python. */
1577 /*****************************************************************************/
1578 static PyObject* Object_getAttr (BPy_Object *obj, char *name)
1580 struct Object * object;
1583 object = obj->object;
1584 if (StringEqual (name, "LocX"))
1585 return (PyFloat_FromDouble(object->loc[0]));
1586 if (StringEqual (name, "LocY"))
1587 return (PyFloat_FromDouble(object->loc[1]));
1588 if (StringEqual (name, "LocZ"))
1589 return (PyFloat_FromDouble(object->loc[2]));
1590 if (StringEqual (name, "loc"))
1591 return (Py_BuildValue ("fff", object->loc[0], object->loc[1],
1593 if (StringEqual (name, "dLocX"))
1594 return (PyFloat_FromDouble(object->dloc[0]));
1595 if (StringEqual (name, "dLocY"))
1596 return (PyFloat_FromDouble(object->dloc[1]));
1597 if (StringEqual (name, "dLocZ"))
1598 return (PyFloat_FromDouble(object->dloc[2]));
1599 if (StringEqual (name, "dloc"))
1600 return (Py_BuildValue ("fff", object->dloc[0], object->dloc[1],
1602 if (StringEqual (name, "RotX"))
1603 return (PyFloat_FromDouble(object->rot[0]));
1604 if (StringEqual (name, "RotY"))
1605 return (PyFloat_FromDouble(object->rot[1]));
1606 if (StringEqual (name, "RotZ"))
1607 return (PyFloat_FromDouble(object->rot[2]));
1608 if (StringEqual (name, "rot"))
1609 return (Py_BuildValue ("fff", object->rot[0], object->rot[1],
1611 if (StringEqual (name, "dRotX"))
1612 return (PyFloat_FromDouble(object->drot[0]));
1613 if (StringEqual (name, "dRotY"))
1614 return (PyFloat_FromDouble(object->drot[1]));
1615 if (StringEqual (name, "dRotZ"))
1616 return (PyFloat_FromDouble(object->drot[2]));
1617 if (StringEqual (name, "drot"))
1618 return (Py_BuildValue ("fff", object->drot[0], object->drot[1],
1620 if (StringEqual (name, "SizeX"))
1621 return (PyFloat_FromDouble(object->size[0]));
1622 if (StringEqual (name, "SizeY"))
1623 return (PyFloat_FromDouble(object->size[1]));
1624 if (StringEqual (name, "SizeZ"))
1625 return (PyFloat_FromDouble(object->size[2]));
1626 if (StringEqual (name, "size"))
1627 return (Py_BuildValue ("fff", object->size[0], object->size[1],
1629 if (StringEqual (name, "dSizeX"))
1630 return (PyFloat_FromDouble(object->dsize[0]));
1631 if (StringEqual (name, "dSizeY"))
1632 return (PyFloat_FromDouble(object->dsize[1]));
1633 if (StringEqual (name, "dSizeZ"))
1634 return (PyFloat_FromDouble(object->dsize[2]));
1635 if (StringEqual (name, "dsize"))
1636 return (Py_BuildValue ("fff", object->dsize[0], object->dsize[1],
1638 if (strncmp (name,"Eff", 3) == 0)
1640 if ( (object->type == OB_IKA) && (object->data != NULL) )
1646 return (PyFloat_FromDouble (ika->effg[0]));
1648 return (PyFloat_FromDouble (ika->effg[1]));
1650 return (PyFloat_FromDouble (ika->effg[2]));
1652 /* Do we need to display a sensible error message here? */
1658 if (StringEqual (name, "Layer"))
1659 return (PyInt_FromLong(object->lay));
1660 if (StringEqual (name, "parent"))
1663 return (Object_CreatePyObject (object->parent));
1666 Py_INCREF (Py_None);
1671 if (StringEqual (name, "track"))
1672 return (Object_CreatePyObject (object->track));
1673 if (StringEqual (name, "data"))
1674 return (Object_getData (obj));
1675 if (StringEqual (name, "ipo"))
1677 if (object->ipo == NULL)
1679 /* There's no ipo linked to the object, return Py_None. */
1680 Py_INCREF (Py_None);
1683 return (Ipo_CreatePyObject (object->ipo));
1685 if (StringEqual (name, "mat"))
1686 return (Object_getMatrix (obj));
1687 if (StringEqual (name, "matrix"))
1688 return (Object_getMatrix (obj));
1689 if (StringEqual (name, "colbits"))
1690 return (Py_BuildValue ("h", object->colbits));
1691 if (StringEqual (name, "drawType"))
1692 return (Py_BuildValue ("b", object->dt));
1693 if (StringEqual (name, "drawMode"))
1694 return (Py_BuildValue ("b", object->dtx));
1695 if (StringEqual (name, "name"))
1696 return (Py_BuildValue ("s", object->id.name+2));
1698 /* not an attribute, search the methods table */
1699 return Py_FindMethod(BPy_Object_methods, (PyObject *)obj, name);
1702 /*****************************************************************************/
1703 /* Function: Object_setAttr */
1704 /* Description: This is a callback function for the BlenObject type. It is */
1705 /* the function that retrieves any value from Python and sets */
1706 /* it accordingly in Blender. */
1707 /*****************************************************************************/
1708 static int Object_setAttr (BPy_Object *obj, char *name, PyObject *value)
1710 PyObject * valtuple;
1711 struct Object * object;
1714 /* First put the value(s) in a tuple. For some variables, we want to */
1715 /* pass the values to a function, and these functions only accept */
1717 valtuple = Py_BuildValue ("(O)", value);
1720 return EXPP_ReturnIntError(PyExc_MemoryError,
1721 "Object_setAttr: couldn't create PyTuple");
1724 object = obj->object;
1725 if (StringEqual (name, "LocX"))
1726 return (!PyArg_Parse (value, "f", &(object->loc[0])));
1727 if (StringEqual (name, "LocY"))
1728 return (!PyArg_Parse (value, "f", &(object->loc[1])));
1729 if (StringEqual (name, "LocZ"))
1730 return (!PyArg_Parse (value, "f", &(object->loc[2])));
1731 if (StringEqual (name, "loc"))
1733 if (Object_setLocation (obj, valtuple) != Py_None)
1738 if (StringEqual (name, "dLocX"))
1739 return (!PyArg_Parse (value, "f", &(object->dloc[0])));
1740 if (StringEqual (name, "dLocY"))
1741 return (!PyArg_Parse (value, "f", &(object->dloc[1])));
1742 if (StringEqual (name, "dLocZ"))
1743 return (!PyArg_Parse (value, "f", &(object->dloc[2])));
1744 if (StringEqual (name, "dloc"))
1746 if (Object_setDeltaLocation (obj, valtuple) != Py_None)
1751 if (StringEqual (name, "RotX"))
1752 return (!PyArg_Parse (value, "f", &(object->rot[0])));
1753 if (StringEqual (name, "RotY"))
1754 return (!PyArg_Parse (value, "f", &(object->rot[1])));
1755 if (StringEqual (name, "RotZ"))
1756 return (!PyArg_Parse (value, "f", &(object->rot[2])));
1757 if (StringEqual (name, "rot"))
1759 if (Object_setEuler (obj, valtuple) != Py_None)
1764 if (StringEqual (name, "dRotX"))
1765 return (!PyArg_Parse (value, "f", &(object->drot[0])));
1766 if (StringEqual (name, "dRotY"))
1767 return (!PyArg_Parse (value, "f", &(object->drot[1])));
1768 if (StringEqual (name, "dRotZ"))
1769 return (!PyArg_Parse (value, "f", &(object->drot[2])));
1770 if (StringEqual (name, "drot"))
1771 return (!PyArg_ParseTuple (value, "fff", &(object->drot[0]),
1772 &(object->drot[1]), &(object->drot[2])));
1773 if (StringEqual (name, "SizeX"))
1774 return (!PyArg_Parse (value, "f", &(object->size[0])));
1775 if (StringEqual (name, "SizeY"))
1776 return (!PyArg_Parse (value, "f", &(object->size[1])));
1777 if (StringEqual (name, "SizeZ"))
1778 return (!PyArg_Parse (value, "f", &(object->size[2])));
1779 if (StringEqual (name, "size"))
1780 return (!PyArg_ParseTuple (value, "fff", &(object->size[0]),
1781 &(object->size[1]), &(object->size[2])));
1782 if (StringEqual (name, "dSizeX"))
1783 return (!PyArg_Parse (value, "f", &(object->dsize[0])));
1784 if (StringEqual (name, "dSizeY"))
1785 return (!PyArg_Parse (value, "f", &(object->dsize[1])));
1786 if (StringEqual (name, "dSizeZ"))
1787 return (!PyArg_Parse (value, "f", &(object->dsize[2])));
1788 if (StringEqual (name, "dsize"))
1789 return (!PyArg_ParseTuple (value, "fff", &(object->dsize[0]),
1790 &(object->dsize[1]), &(object->dsize[2])));
1791 if (strncmp (name,"Eff", 3) == 0)
1793 if ( (object->type == OB_IKA) && (object->data != NULL) )
1799 return (!PyArg_Parse (value, "f", &(ika->effg[0])));
1801 return (!PyArg_Parse (value, "f", &(ika->effg[1])));
1803 return (!PyArg_Parse (value, "f", &(ika->effg[2])));
1805 /* Do we need to display a sensible error message here? */
1811 if (StringEqual (name, "Layer"))
1812 return (!PyArg_Parse (value, "i", &(object->lay)));
1813 if (StringEqual (name, "parent"))
1815 /* This is not allowed. */
1816 PythonReturnErrorObject (PyExc_AttributeError,
1817 "Setting the parent is not allowed.");
1820 if (StringEqual (name, "track"))
1822 /* This is not allowed. */
1823 PythonReturnErrorObject (PyExc_AttributeError,
1824 "Setting the track is not allowed.");
1827 if (StringEqual (name, "data"))
1829 /* This is not allowed. */
1830 PythonReturnErrorObject (PyExc_AttributeError,
1831 "Setting the data is not allowed.");
1834 if (StringEqual (name, "ipo"))
1836 /* This is not allowed. */
1837 PythonReturnErrorObject (PyExc_AttributeError,
1838 "Setting the ipo is not allowed.");
1841 if (StringEqual (name, "mat"))
1843 /* This is not allowed. */
1844 PythonReturnErrorObject (PyExc_AttributeError,
1845 "Setting the matrix is not allowed.");
1848 if (StringEqual (name, "matrix"))
1850 /* This is not allowed. */
1851 PythonReturnErrorObject (PyExc_AttributeError,
1852 "Please use .setMatrix(matrix)");
1855 if (StringEqual (name, "colbits"))
1856 return (!PyArg_Parse (value, "h", &(object->colbits)));
1857 if (StringEqual (name, "drawType"))
1859 if (Object_setDrawType (obj, valtuple) != Py_None)
1864 if (StringEqual (name, "drawMode"))
1866 if (Object_setDrawMode (obj, valtuple) != Py_None)
1871 if (StringEqual (name, "name"))
1873 if (Object_setName (obj, valtuple) != Py_None)
1879 printf ("Unknown variable.\n");
1883 /*****************************************************************************/
1884 /* Function: Object_compare */
1885 /* Description: This is a callback function for the BPy_Object type. It */
1886 /* compares two Object_Type objects. Only the "==" and "!=" */
1887 /* comparisons are meaninful. Returns 0 for equality and -1 if */
1888 /* they don't point to the same Blender Object struct. */
1889 /* In Python it becomes 1 if they are equal, 0 otherwise. */
1890 /*****************************************************************************/
1891 static int Object_compare (BPy_Object *a, BPy_Object *b)
1893 Object *pa = a->object, *pb = b->object;
1894 return (pa == pb) ? 0:-1;
1897 /*****************************************************************************/
1898 /* Function: Object_repr */
1899 /* Description: This is a callback function for the BPy_Object type. It */
1900 /* builds a meaninful string to represent object objects. */
1901 /*****************************************************************************/
1902 static PyObject *Object_repr (BPy_Object *self)
1904 return PyString_FromFormat("[Object \"%s\"]", self->object->id.name+2);