* Fixed problems in with script linking.
I had to update many files to get this to work.
This commit is contained in:
@@ -96,7 +96,6 @@ PyObject *blender_import(PyObject *self, PyObject *args);
|
||||
/*****************************************************************************/
|
||||
void BPY_start_python(void)
|
||||
{
|
||||
//printf ("In BPY_start_python\n");
|
||||
/* TODO: Shouldn't "blender" be replaced by PACKAGE ?? (config.h) */
|
||||
Py_SetProgramName("blender");
|
||||
|
||||
@@ -116,7 +115,6 @@ void BPY_start_python(void)
|
||||
/*****************************************************************************/
|
||||
void BPY_end_python(void)
|
||||
{
|
||||
//printf ("In BPY_end_python\n");
|
||||
Py_Finalize();
|
||||
return;
|
||||
}
|
||||
@@ -214,7 +212,6 @@ void BPY_syspath_append_pythondir(void)
|
||||
/*****************************************************************************/
|
||||
int BPY_Err_getLinenumber(void)
|
||||
{
|
||||
//printf ("In BPY_Err_getLinenumber\n");
|
||||
return g_script_error.lineno;
|
||||
}
|
||||
|
||||
@@ -223,7 +220,6 @@ int BPY_Err_getLinenumber(void)
|
||||
/*****************************************************************************/
|
||||
const char *BPY_Err_getFilename(void)
|
||||
{
|
||||
//printf ("In BPY_Err_getFilename\n");
|
||||
return g_script_error.filename;
|
||||
}
|
||||
|
||||
@@ -321,8 +317,6 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
|
||||
PyObject *dict, *ret;
|
||||
PyObject *main_dict = PyModule_GetDict(PyImport_AddModule("__main__"));
|
||||
|
||||
//printf ("\nIn BPY_txt_do_python\n");
|
||||
|
||||
if (!st->text) return NULL;
|
||||
|
||||
/* The EXPP_releaseGlobalDict global variable controls whether we should run
|
||||
@@ -401,7 +395,6 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
|
||||
/*****************************************************************************/
|
||||
void BPY_free_compiled_text(struct Text* text)
|
||||
{
|
||||
//printf ("In BPY_free_compiled_text\n");
|
||||
if (!text->compiled) return;
|
||||
Py_DECREF((PyObject*) text->compiled);
|
||||
text->compiled = NULL;
|
||||
@@ -419,7 +412,6 @@ void BPY_free_compiled_text(struct Text* text)
|
||||
/*****************************************************************************/
|
||||
void BPY_clear_bad_scriptlinks(struct Text *byebye)
|
||||
{
|
||||
//printf ("In BPY_clear_bad_scriptlinks\n");
|
||||
/*
|
||||
BPY_clear_bad_scriptlist(getObjectList(), byebye);
|
||||
BPY_clear_bad_scriptlist(getLampList(), byebye);
|
||||
@@ -441,8 +433,6 @@ void BPY_clear_bad_scriptlinks(struct Text *byebye)
|
||||
/*****************************************************************************/
|
||||
void BPY_do_all_scripts(short event)
|
||||
{
|
||||
/*printf ("In BPY_do_all_scripts(event=%d)\n",event);*/
|
||||
|
||||
DoAllScriptsFromList (&(G.main->object), event);
|
||||
DoAllScriptsFromList (&(G.main->lamp), event);
|
||||
DoAllScriptsFromList (&(G.main->camera), event);
|
||||
@@ -468,16 +458,12 @@ void BPY_do_pyscript(struct ID *id, short event)
|
||||
PyObject * dict;
|
||||
PyObject * ret;
|
||||
|
||||
/*printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event);*/
|
||||
|
||||
scriptlink = setScriptLinks (id, event);
|
||||
|
||||
if (scriptlink == NULL) return;
|
||||
|
||||
for (index = 0; index < scriptlink->totscript; index++)
|
||||
{
|
||||
/*printf ("scriptnr: %d\tevent=%d, flag[index]=%d\n", index,
|
||||
event, scriptlink->flag[index]);*/
|
||||
if ((scriptlink->flag[index] == event) &&
|
||||
(scriptlink->scripts[index] != NULL))
|
||||
{
|
||||
@@ -507,8 +493,6 @@ void BPY_do_pyscript(struct ID *id, short event)
|
||||
/*****************************************************************************/
|
||||
void BPY_free_scriptlink(struct ScriptLink *slink)
|
||||
{
|
||||
//printf ("In BPY_free_scriptlink\n");
|
||||
|
||||
if (slink->totscript) {
|
||||
if(slink->flag) MEM_freeN(slink->flag);
|
||||
if(slink->scripts) MEM_freeN(slink->scripts);
|
||||
@@ -525,8 +509,6 @@ void BPY_copy_scriptlink(struct ScriptLink *scriptlink)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
//printf ("In BPY_copy_scriptlink\n");
|
||||
|
||||
if (scriptlink->totscript) {
|
||||
|
||||
tmp = scriptlink->scripts;
|
||||
@@ -566,8 +548,6 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
|
||||
{
|
||||
char *buf = NULL;
|
||||
|
||||
printf("Run Python script \"%s\" ...\n", GetName(text));
|
||||
|
||||
/* The script text is compiled to Python bytecode and saved at text->compiled
|
||||
* to speed-up execution if the user executes the script multiple times */
|
||||
|
||||
|
||||
@@ -217,6 +217,32 @@ Camera *Camera_FromPyObject (PyObject *pyobj)
|
||||
return ((BPy_Camera *)pyobj)->camera;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Camera * GetCameraByName (char * name)
|
||||
{
|
||||
Camera * cam_iter;
|
||||
|
||||
cam_iter = G.main->camera.first;
|
||||
while (cam_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(cam_iter->id))))
|
||||
{
|
||||
return (cam_iter);
|
||||
}
|
||||
cam_iter = cam_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no camera with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -79,10 +79,14 @@ ScriptLink * setScriptLinks(ID *id, short event)
|
||||
ScriptLink * scriptlink;
|
||||
PyObject * link;
|
||||
Object * object;
|
||||
Lamp * lamp;
|
||||
Camera * camera;
|
||||
Material * material;
|
||||
Scene * scene;
|
||||
World * world;
|
||||
int obj_id;
|
||||
|
||||
obj_id = MAKE_ID2 (id->name[0], id->name[1]);
|
||||
//printf ("In setScriptLinks (id=%s, event=%d)\n",id->name, event);
|
||||
|
||||
switch (obj_id)
|
||||
{
|
||||
@@ -96,29 +100,49 @@ ScriptLink * setScriptLinks(ID *id, short event)
|
||||
scriptlink = &(object->scriptlink);
|
||||
break;
|
||||
case ID_LA:
|
||||
scriptlink = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
link = Py_None;
|
||||
lamp = GetLampByName (GetIdName (id));
|
||||
if (lamp == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
link = Lamp_CreatePyObject (lamp);
|
||||
scriptlink = &(lamp->scriptlink);
|
||||
break;
|
||||
case ID_CA:
|
||||
scriptlink = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
link = Py_None;
|
||||
camera = GetCameraByName (GetIdName (id));
|
||||
if (camera == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
link = Camera_CreatePyObject (camera);
|
||||
scriptlink = &(camera->scriptlink);
|
||||
break;
|
||||
case ID_MA:
|
||||
scriptlink = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
link = Py_None;
|
||||
material = GetMaterialByName (GetIdName (id));
|
||||
if (material == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
link = Material_CreatePyObject (material);
|
||||
scriptlink = &(material->scriptlink);
|
||||
break;
|
||||
case ID_WO:
|
||||
scriptlink = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
link = Py_None;
|
||||
world = GetWorldByName (GetIdName (id));
|
||||
if (world == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
link = World_CreatePyObject (world);
|
||||
scriptlink = &(world->scriptlink);
|
||||
break;
|
||||
case ID_SCE:
|
||||
scriptlink = NULL;
|
||||
Py_INCREF(Py_None);
|
||||
link = Py_None;
|
||||
scene = GetSceneByName (GetIdName (id));
|
||||
if (scene == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
link = Scene_CreatePyObject (scene);
|
||||
scriptlink = &(scene->scriptlink);
|
||||
break;
|
||||
default:
|
||||
//Py_INCREF(Py_None);
|
||||
@@ -131,9 +155,9 @@ ScriptLink * setScriptLinks(ID *id, short event)
|
||||
if (scriptlink == NULL)
|
||||
{
|
||||
/* This is probably not an internal error anymore :)
|
||||
TODO: Check this
|
||||
TODO: Check this */
|
||||
printf ("Internal error, unable to create PyBlock for script link\n");
|
||||
*/
|
||||
|
||||
Py_INCREF(Py_False);
|
||||
PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
|
||||
return NULL;
|
||||
|
||||
@@ -289,6 +289,32 @@ Lamp *Lamp_FromPyObject (PyObject *pyobj)
|
||||
return ((BPy_Lamp *)pyobj)->lamp;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the lamp with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the lamp name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no lamp with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Lamp * GetLampByName (char * name)
|
||||
{
|
||||
Lamp * lamp_iter;
|
||||
|
||||
lamp_iter = G.main->lamp.first;
|
||||
while (lamp_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(lamp_iter->id))))
|
||||
{
|
||||
return lamp_iter;
|
||||
}
|
||||
lamp_iter = lamp_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no lamp with the given name */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Lamp methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -583,6 +583,32 @@ int Material_CheckPyObject (PyObject *pyobj)
|
||||
return (pyobj->ob_type == &Material_Type);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Material * GetMaterialByName (char * name)
|
||||
{
|
||||
Material * mat_iter;
|
||||
|
||||
mat_iter = G.main->mat.first;
|
||||
while (mat_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(mat_iter->id))))
|
||||
{
|
||||
return (mat_iter);
|
||||
}
|
||||
mat_iter = mat_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no material with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Material methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -1252,6 +1252,32 @@ struct Object* Object_FromPyObject (PyObject *py_obj)
|
||||
return (blen_obj->object);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Object * GetObjectByName (char * name)
|
||||
{
|
||||
Object * obj_iter;
|
||||
|
||||
obj_iter = G.main->object.first;
|
||||
while (obj_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(obj_iter->id))))
|
||||
{
|
||||
return (obj_iter);
|
||||
}
|
||||
obj_iter = obj_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no object with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Object_dealloc */
|
||||
/* Description: This is a callback function for the BlenObject type. It is */
|
||||
@@ -1351,13 +1377,15 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
|
||||
if (StringEqual (name, "Layer"))
|
||||
return (PyInt_FromLong(object->lay));
|
||||
if (StringEqual (name, "parent"))
|
||||
if (object->parent)
|
||||
return (Object_CreatePyObject (object->parent));
|
||||
else
|
||||
{
|
||||
Py_INCREF (Py_None);
|
||||
return (Py_None);
|
||||
}
|
||||
{
|
||||
if (object->parent)
|
||||
return (Object_CreatePyObject (object->parent));
|
||||
else
|
||||
{
|
||||
Py_INCREF (Py_None);
|
||||
return (Py_None);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringEqual (name, "track"))
|
||||
return (Object_CreatePyObject (object->track));
|
||||
@@ -1371,7 +1399,9 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
|
||||
/* However, if there's already some kind of reference in the */
|
||||
/* Python object, we also need to free that one. */
|
||||
if (obj->ipo != NULL)
|
||||
{
|
||||
Py_DECREF (obj->ipo);
|
||||
}
|
||||
|
||||
/* There's no ipo, so this needs to be NULL always. */
|
||||
obj->ipo = NULL;
|
||||
@@ -1612,3 +1642,4 @@ static PyObject *Object_repr (BPy_Object *self)
|
||||
{
|
||||
return PyString_FromFormat("[Object \"%s\"]", self->object->id.name+2);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,6 +363,32 @@ Scene *Scene_FromPyObject (PyObject *pyobj)
|
||||
return ((BPy_Scene *)pyobj)->scene;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Scene * GetSceneByName (char * name)
|
||||
{
|
||||
Scene * scene_iter;
|
||||
|
||||
scene_iter = G.main->scene.first;
|
||||
while (scene_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(scene_iter->id))))
|
||||
{
|
||||
return (scene_iter);
|
||||
}
|
||||
scene_iter = scene_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no object with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Scene methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -687,7 +687,7 @@ return (py_obj->ob_type == &World_Type);
|
||||
}
|
||||
|
||||
|
||||
struct World* World_FromPyObject (PyObject *py_obj)
|
||||
World* World_FromPyObject (PyObject *py_obj)
|
||||
{
|
||||
BPy_World * blen_obj;
|
||||
|
||||
@@ -696,3 +696,29 @@ struct World* World_FromPyObject (PyObject *py_obj)
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
World * GetWorldByName (char * name)
|
||||
{
|
||||
World * world_iter;
|
||||
|
||||
world_iter = G.main->world.first;
|
||||
while (world_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(world_iter->id))))
|
||||
{
|
||||
return (world_iter);
|
||||
}
|
||||
world_iter = world_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no object with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,32 +142,6 @@ char * event_to_name(short event)
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Returns the object with the name specified by the argument */
|
||||
/* name. Note that the calling function has to remove the first */
|
||||
/* two characters of the object name. These two characters */
|
||||
/* specify the type of the object (OB, ME, WO, ...) */
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
struct Object * GetObjectByName (char * name)
|
||||
{
|
||||
Object * obj_iter;
|
||||
|
||||
obj_iter = G.main->object.first;
|
||||
while (obj_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(obj_iter->id))))
|
||||
{
|
||||
return (obj_iter);
|
||||
}
|
||||
obj_iter = obj_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no object with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Checks whether all objects in a PySequence are of a same */
|
||||
/* given type. Returns 0 if not, 1 on success. */
|
||||
|
||||
@@ -63,10 +63,4 @@ int EXPP_ReturnIntError (PyObject *type, char *error_msg);
|
||||
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
|
||||
PyObject *EXPP_tuple_repr(PyObject *self, int size);
|
||||
|
||||
/* The following functions may need to be moved to the respective BKE or */
|
||||
/* DNA modules. */
|
||||
|
||||
struct Object * GetObjectByName (char * name);
|
||||
|
||||
|
||||
#endif /* EXPP_gen_utils_h */
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <DNA_meta_types.h>
|
||||
#include <DNA_image_types.h>
|
||||
#include <DNA_text_types.h>
|
||||
#include <DNA_world_types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
@@ -67,12 +68,14 @@ PyObject * Object_Init (void);
|
||||
PyObject * Object_CreatePyObject (struct Object *obj);
|
||||
Object * Object_FromPyObject (PyObject *py_obj);
|
||||
int Object_CheckPyObject (PyObject *py_obj);
|
||||
Object * GetObjectByName (char * name);
|
||||
|
||||
/* Scene */
|
||||
PyObject * Scene_Init (void);
|
||||
PyObject * Scene_CreatePyObject (struct Scene *sce);
|
||||
Scene * Scene_FromPyObject (PyObject *pyobj);
|
||||
int Scene_CheckPyObject (PyObject *pyobj);
|
||||
Scene * GetSceneByName (char * name);
|
||||
|
||||
/* Types */
|
||||
PyObject * Types_Init (void);
|
||||
@@ -93,18 +96,21 @@ int EXPP_releaseMaterialList (Material **matlist, int len);
|
||||
int EXPP_synchronizeMaterialLists (Object *object, void *data);
|
||||
void EXPP_incr_mats_us (Material **matlist, int len);
|
||||
PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len);
|
||||
Material * GetMaterialByName (char * name);
|
||||
|
||||
/* Camera Data */
|
||||
PyObject * Camera_Init (void);
|
||||
PyObject * Camera_CreatePyObject (struct Camera *cam);
|
||||
Camera * Camera_FromPyObject (PyObject *pyobj);
|
||||
int Camera_CheckPyObject (PyObject *pyobj);
|
||||
Camera * GetCameraByName (char * name);
|
||||
|
||||
/* Lamp Data */
|
||||
PyObject * Lamp_Init (void);
|
||||
PyObject * Lamp_CreatePyObject (struct Lamp *lamp);
|
||||
Lamp * Lamp_FromPyObject (PyObject *pyobj);
|
||||
int Lamp_CheckPyObject (PyObject *pyobj);
|
||||
Lamp * GetLampByName (char * name);
|
||||
|
||||
/* Curve Data */
|
||||
PyObject * Curve_Init (void);
|
||||
@@ -154,10 +160,16 @@ int Image_CheckPyObject (PyObject *pyobj);
|
||||
PyObject * Text_Init (void);
|
||||
PyObject * Text_CreatePyObject (Text *txt);
|
||||
|
||||
/* World */
|
||||
PyObject * World_Init (void);
|
||||
PyObject * World_CreatePyObject (struct World *world);
|
||||
int World_CheckPyObject (PyObject *py_obj);
|
||||
World * World_FromPyObject (PyObject *py_obj);
|
||||
World * GetWorldByName (char * name);
|
||||
|
||||
/* Init functions for other modules */
|
||||
PyObject * Window_Init (void);
|
||||
PyObject * Draw_Init (void);
|
||||
PyObject * BGL_Init (void);
|
||||
PyObject * World_Init (void);
|
||||
|
||||
#endif /* EXPP_modules_h */
|
||||
|
||||
Reference in New Issue
Block a user