513
511
matrix is not updated for changes made by the script itself\n\
514
512
(like obj.LocX = 10) until a redraw happens, either called by the script or\n\
515
513
automatic when the script finishes."},
516
{"getName", ( PyCFunction ) Object_getName, METH_NOARGS,
514
{"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
517
515
"Returns the name of the object"},
518
516
{"getParent", ( PyCFunction ) Object_getParent, METH_NOARGS,
519
517
"Returns the object's parent object"},
694
692
{"setMaterials", ( PyCFunction ) Object_setMaterials, METH_VARARGS,
695
693
"Sets materials. The argument must be a list of valid material\n\
697
{"setName", ( PyCFunction ) Object_SetName, METH_VARARGS,
695
{"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
698
696
"Sets the name of the object"},
699
697
{"setSize", ( PyCFunction ) Object_setSize, METH_VARARGS,
700
698
"Set the object's size. The first argument must be a vector\n\
758
756
"([s1<,s2,s3...>]) - Delete specified scriptlinks from this object."},
759
757
{"insertShapeKey", ( PyCFunction ) Object_insertShapeKey, METH_NOARGS,
760
758
"() - Insert a Shape Key in the current object"},
761
{"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS,
762
"() - Return a copy of this object."},
763
759
{"getProperties", ( PyCFunction ) Object_GetProperties, METH_NOARGS,
764
760
"() return a reference to the ID properties associated with this object."},
761
{"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS,
762
"() - Return a copy of this object."},
763
{"copy", ( PyCFunction ) Object_copy, METH_NOARGS,
764
"() - Return a copy of this object."},
765
765
{NULL, NULL, 0, NULL}
989
989
static char *kwlist[] = {"mesh", "surface", "curve",
990
990
"text", "metaball", "armature", "lamp", "material", "texture", "ipo", NULL};
992
/* duplicating in background causes segfaults */
993
if( G.background == 1 )
994
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
995
"cannot duplicate objects in background mode" );
992
998
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|iiiiiiiiii", kwlist,
993
999
&mesh_dupe, &surface_dupe, &curve_dupe, &text_dupe, &metaball_dupe,
994
1000
&armature_dupe, &lamp_dupe, &material_dupe, &texture_dupe, &ipo_dupe))
1099
1105
switch ( object->type ) {
1100
1106
case OB_ARMATURE:
1101
1107
/* TODO: Do we need to add something to G? (see the OB_LAMP case) */
1102
object->data = add_armature( );
1108
object->data = add_armature( "Armature" );
1104
1110
case OB_CAMERA:
1105
1111
/* TODO: Do we need to add something to G? (see the OB_LAMP case) */
1106
object->data = add_camera( );
1112
object->data = add_camera( "Camera" );
1109
object->data = add_curve( OB_CURVE );
1115
object->data = add_curve( "Curve", OB_CURVE );
1113
object->data = add_lamp( );
1119
object->data = add_lamp( "Lamp" );
1117
object->data = add_mesh( );
1123
object->data = add_mesh( "Mesh" );
1120
1126
case OB_LATTICE:
1121
object->data = ( void * ) add_lattice( );
1127
object->data = ( void * ) add_lattice( "Lattice" );
1122
1128
object->dt = OB_WIRE;
1125
object->data = add_mball( );
1131
object->data = add_mball( "Meta" );
1128
1134
/* TODO the following types will be supported later,
1586
1588
return EXPP_ReturnPyObjError( PyExc_TypeError,
1587
1589
"expected an object as argument" );
1589
if( ArmatureObject_Check( py_data ) )
1591
if( BPy_Armature_Check( py_data ) )
1590
1592
data = ( void * ) PyArmature_AsArmature((BPy_Armature*)py_data);
1591
else if( Camera_CheckPyObject( py_data ) )
1593
else if( BPy_Camera_Check( py_data ) )
1592
1594
data = ( void * ) Camera_FromPyObject( py_data );
1593
else if( Lamp_CheckPyObject( py_data ) )
1595
else if( BPy_Lamp_Check( py_data ) )
1594
1596
data = ( void * ) Lamp_FromPyObject( py_data );
1595
else if( Curve_CheckPyObject( py_data ) )
1597
else if( BPy_Curve_Check( py_data ) )
1596
1598
data = ( void * ) Curve_FromPyObject( py_data );
1597
else if( NMesh_CheckPyObject( py_data ) ) {
1599
else if( BPy_NMesh_Check( py_data ) ) {
1598
1600
data = ( void * ) NMesh_FromPyObject( py_data, self->object );
1599
1601
if( !data ) /* NULL means there is already an error */
1601
} else if( Mesh_CheckPyObject( py_data ) )
1603
} else if( BPy_Mesh_Check( py_data ) )
1602
1604
data = ( void * ) Mesh_FromPyObject( py_data, self->object );
1603
else if( Lattice_CheckPyObject( py_data ) )
1605
else if( BPy_Lattice_Check( py_data ) )
1604
1606
data = ( void * ) Lattice_FromPyObject( py_data );
1605
else if( Metaball_CheckPyObject( py_data ) )
1607
else if( BPy_Metaball_Check( py_data ) )
1606
1608
data = ( void * ) Metaball_FromPyObject( py_data );
1607
else if( Text3d_CheckPyObject( py_data ) )
1609
else if( BPy_Text3d_Check( py_data ) )
1608
1610
data = ( void * ) Text3d_FromPyObject( py_data );
1610
1612
/* have we set data to something good? */
3002
2999
Py_RETURN_NONE;
3005
static int Object_setDupliGroup( BPy_Object * self, BPy_Group * args )
3002
static int Object_setDupliGroup( BPy_Object * self, PyObject * value )
3007
Object *ob= self->object;
3009
if( (PyObject *)args == Py_None ) {
3011
ob->dup_group->id.us--;
3013
ob->dup_group = NULL;
3014
} else if( BPy_Group_Check( args ) ) {
3016
ob->dup_group->id.us--;
3018
ob->dup_group = args->group;
3019
id_us_plus(&ob->dup_group->id);
3021
return EXPP_ReturnIntError( PyExc_TypeError,
3022
"expected a group or None" );
3004
return GenericLib_assignData(value, (void **) &self->object->dup_group, 0, 1, ID_GR, 0);
3027
3007
static PyObject *Object_getEffects( BPy_Object * self )
3157
3125
/*****************************************************************************/
3158
/* Description: Returns the object with the name specified by the argument */
3159
/* name. Note that the calling function has to remove the first */
3160
/* two characters of the object name. These two characters */
3161
/* specify the type of the object (OB, ME, WO, ...) */
3162
/* The function will return NULL when no object with the given */
3163
/* name is found. */
3164
/*****************************************************************************/
3165
Object *GetObjectByName( char *name )
3169
obj_iter = G.main->object.first;
3171
if( StringEqual( name, GetIdName( &( obj_iter->id ) ) ) ) {
3172
return ( obj_iter );
3174
obj_iter = obj_iter->id.next;
3177
/* There is no object with the given name */
3181
/*****************************************************************************/
3182
3126
/* Function: Object_dealloc */
3183
3127
/* Description: This is a callback function for the BlenObject type. It is */
3184
3128
/* the destructor function. */
4353
4298
static int Object_setIpo( BPy_Object * self, PyObject * value )
4356
Ipo *oldipo = self->object->ipo;
4359
/* if parameter is not None, check for valid Ipo */
4361
if ( value != Py_None ) {
4362
if ( !Ipo_CheckPyObject( value ) )
4363
return EXPP_ReturnIntError( PyExc_TypeError,
4364
"expected an Ipo object" );
4366
ipo = Ipo_FromPyObject( value );
4369
return EXPP_ReturnIntError( PyExc_RuntimeError,
4372
if( ipo->blocktype != ID_OB )
4373
return EXPP_ReturnIntError( PyExc_TypeError,
4374
"Ipo is not a object data Ipo" );
4377
/* if already linked to Ipo, delete link */
4385
/* assign new Ipo and increment user count, or set to NULL if deleting */
4387
self->object->ipo = ipo;
4389
id_us_plus(&ipo->id);
4394
static PyObject *Object_getOopsLoc( BPy_Object * self )
4397
Oops *oops = G.soops->oops.first;
4399
if( oops->type == ID_OB && (Object *)oops->id == self->object )
4400
return Py_BuildValue( "ff", oops->x, oops->y );
4407
static PyObject *Object_getOopsSel ( BPy_Object * self )
4410
Oops *oops= G.soops->oops.first;
4412
if( oops->type == ID_OB
4413
&& (Object *)oops->id == self->object ) {
4414
if( oops->flag & SELECT )
4425
static int Object_setOopsLoc( BPy_Object * self, PyObject * value )
4428
Oops *oops= G.soops->oops.first;
4430
if( oops->type == ID_OB && (Object *)oops->id == self->object ) {
4431
if( !PyArg_ParseTuple( value, "ff", &oops->x, &oops->y ) )
4432
return EXPP_ReturnIntError( PyExc_TypeError,
4433
"expected two floats as arguments" );
4438
return EXPP_ReturnIntError( PyExc_RuntimeError,
4439
"couldn't find oopsLoc data for object" );
4444
static int Object_setOopsSel( BPy_Object * self, PyObject * value )
4446
int setting = PyObject_IsTrue( value );
4449
return EXPP_ReturnIntError( PyExc_TypeError,
4450
"expected true/false argument" );
4453
Oops *oops = G.soops->oops.first;
4455
if( oops->type==ID_OB ) {
4456
if( (Object *)oops->id == self->object ) {
4458
/* this code is what other modules do; it doesn't seem to work */
4460
oops->flag &= ~SELECT;
4462
oops->flag |= SELECT;
4464
printf ("warning: Object.oopsSel setter may not be coded correctly\n");
4465
/* this code seems to work, but may not be the correct thing to do */
4467
self->object->flag &= ~SELECT;
4469
self->object->flag |= SELECT;
4300
return GenericLib_assignData(value, (void **) &self->object->ipo, 0, 1, ID_IP, ID_OB);
4480
4303
static int Object_setTracked( BPy_Object * self, PyObject * value )
4482
Object *ob = self->object;
4484
if( value != Py_None && !BPy_Object_Check( value ) )
4485
return EXPP_ReturnIntError( PyExc_TypeError,
4486
"expected an object argument" );
4488
if( value != Py_None )
4489
ob->track = ((BPy_Object *)value)->object;
4491
ob->track = ((BPy_Object *)value)->object;
4492
self->object->recalc |= OB_RECALC_OB;
4493
DAG_scene_sort( G.scene );
4498
static PyObject *Object_getUsers( BPy_Object * self )
4500
return PyInt_FromLong( self->object->id.us );
4503
static PyObject *Object_getFakeUser( BPy_Object * self )
4505
if (self->object->id.flag & LIB_FAKEUSER)
4511
static int Object_setFakeUser( BPy_Object * self, PyObject * value )
4513
return SetIdFakeUser(&self->object->id, value);
4306
ret = GenericLib_assignData(value, (void **) &self->object->track, 0, 0, ID_OB, 0);
4308
self->object->recalc |= OB_RECALC_OB;
4309
DAG_scene_sort( G.scene );
4516
4314
/* Localspace matrix */
4917
4714
(getter)Object_getMatrixOldWorld, (setter)NULL,
4918
4715
"old-type worldspace matrix (prior to Blender 2.34)",
4921
(getter)Object_getName, (setter)Object_setName,
4925
(getter)Object_getOopsLoc, (setter)Object_setOopsLoc,
4926
"Object OOPs location",
4929
(getter)Object_getOopsSel, (setter)Object_setOopsSel,
4930
"Object OOPs selection flag",
4933
4718
(getter)get_obj_data, (setter)NULL,
4934
4719
"The Datablock object linked to this object",
4962
4747
"The bounding box of this object",
4965
(getter)Object_getAction, (setter)NULL,
4750
(getter)Object_getAction, (setter)Object_setAction,
4966
4751
"The action associated with this object (if defined)",
4968
4753
{"game_properties",
4969
4754
(getter)Object_getAllProperties, (setter)NULL,
4970
4755
"The object's properties",
4973
(getter)Object_getUsers, (setter)NULL,
4974
"The number of object users",
4977
(getter)Object_getFakeUser, (setter)Object_setFakeUser,
4978
"The fake user status of this object",
4982
4759
(getter)getFloatAttr, (setter)setFloatAttrClamp,
5351
5128
BPy_constant *d = ( BPy_constant * ) M;
5352
5129
PyConstant_Insert( d, "OBJECT", PyInt_FromLong( PAROBJECT ) );
5353
5130
PyConstant_Insert( d, "CURVE", PyInt_FromLong( PARCURVE ) );
5354
PyConstant_Insert( d, "LATTICE", PyInt_FromLong( PARKEY ) );
5132
/* 2.43 was released as LATTICE as PARKEY, my bad,
5133
lattice uses PARSKEL also - Campbell */
5134
PyConstant_Insert( d, "LATTICE", PyInt_FromLong( PARSKEL ) );
5355
5136
PyConstant_Insert( d, "ARMATURE", PyInt_FromLong( PARSKEL ) );
5356
5137
PyConstant_Insert( d, "VERT1", PyInt_FromLong( PARVERT1 ) );
5357
5138
PyConstant_Insert( d, "VERT3", PyInt_FromLong( PARVERT3 ) );
5223
static PyObject *M_Object_IpoKeyTypesDict( void )
5225
PyObject *M = PyConstant_New( );
5228
BPy_constant *d = ( BPy_constant * ) M;
5229
PyConstant_Insert( d, "LOC", PyInt_FromLong( IPOKEY_LOC ) );
5230
PyConstant_Insert( d, "ROT", PyInt_FromLong( IPOKEY_ROT ) );
5231
PyConstant_Insert( d, "SIZE", PyInt_FromLong( IPOKEY_SIZE ) );
5232
PyConstant_Insert( d, "LOCROT", PyInt_FromLong( IPOKEY_LOCROT ) );
5233
PyConstant_Insert( d, "LOCROTSIZE", PyInt_FromLong( IPOKEY_LOCROTSIZE ) );
5235
PyConstant_Insert( d, "PI_STRENGTH", PyInt_FromLong( IPOKEY_PI_STRENGTH ) );
5236
PyConstant_Insert( d, "PI_FALLOFF", PyInt_FromLong( IPOKEY_PI_FALLOFF ) );
5237
PyConstant_Insert( d, "PI_SURFACEDAMP", PyInt_FromLong( IPOKEY_PI_SURFACEDAMP ) );
5238
PyConstant_Insert( d, "PI_RANDOMDAMP", PyInt_FromLong( IPOKEY_PI_RANDOMDAMP ) );
5239
PyConstant_Insert( d, "PI_PERM", PyInt_FromLong( IPOKEY_PI_PERM ) );
5442
5244
/*****************************************************************************/
5443
5245
/* Function: initObject */
5444
5246
/*****************************************************************************/
5452
5254
PyObject *PITypesDict = M_Object_PITypesDict( );
5453
5255
PyObject *RBFlagsDict = M_Object_RBFlagsDict( );
5454
5256
PyObject *RBShapesDict = M_Object_RBShapeBoundDict( );
5257
PyObject *IpoKeyTypesDict = M_Object_IpoKeyTypesDict( );
5456
5259
PyType_Ready( &Object_Type ) ;
5458
5261
module = Py_InitModule3( "Blender.Object", M_Object_methods,
5459
5262
M_Object_doc );
5265
/* We Should Remove these!!!! */
5461
5266
PyModule_AddIntConstant( module, "LOC", IPOKEY_LOC );
5462
5267
PyModule_AddIntConstant( module, "ROT", IPOKEY_ROT );
5463
5268
PyModule_AddIntConstant( module, "SIZE", IPOKEY_SIZE );