* Implemented the BPY_do_all_scripts interface function (BPY_interface.c)
authorMichel Selten <michel@mselten.demon.nl>
Wed, 19 Mar 2003 18:57:23 +0000 (18:57 +0000)
committerMichel Selten <michel@mselten.demon.nl>
Wed, 19 Mar 2003 18:57:23 +0000 (18:57 +0000)
* Created a function to return all scripts from a linked list
  (DoAllScriptsFromList).

Michel

source/blender/python/BPY_interface.c

index ce63eace5011e48fc19d2a164feff4fbccad1b7b..d205f790f90a7c8d15cdf8517482b08cdcbb9b54 100644 (file)
 
 #include <MEM_guardedalloc.h>
 
+#include <BKE_global.h>
+#include <BKE_main.h>
 #include <BKE_text.h>
+#include <DNA_camera_types.h>
 #include <DNA_ID.h>
+#include <DNA_lamp_types.h>
+#include <DNA_material_types.h>
+#include <DNA_object_types.h>
+#include <DNA_scene_types.h>
 #include <DNA_scriptlink_types.h>
 #include <DNA_space_types.h>
 #include <DNA_text_types.h>
+#include <DNA_world_types.h>
 
-#include <BPY_extern.h>
+#include "BPY_extern.h"
 
 #include "api2_2x/interface.h"
-/* unfortunately the following #include is needed because of some missing */
-/* functionality in BKE/DNA */
-/* #include "api2_2x/gen_utils.h" */
 
 /*****************************************************************************/
 /* Structure definitions                                                     */
@@ -70,6 +75,7 @@ PyObject * RunPython(Text *text, PyObject *globaldict);
 char *     GetName(Text *text);
 PyObject * CreateGlobalDictionary (void);
 void       ReleaseGlobalDictionary (PyObject * dict);
+void       DoAllScriptsFromList (ListBase * list, short event);
 
 /*****************************************************************************/
 /* Description: This function will initialise Python and all the implemented */
@@ -163,12 +169,22 @@ void BPY_clear_bad_scriptlinks(struct Text *byebye)
 }
 
 /*****************************************************************************/
-/* Description:                                                              */
-/* Notes:       Not implemented yet                                          */
+/* Description: Loop through all scripts of a list of object types, and      */
+/*              execute these scripts.                                       */
+/*              For the scene, only the current active scene the scripts are */
+/*              executed (if any).                                           */
 /*****************************************************************************/
 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);
+       DoAllScriptsFromList (&(G.main->mat), event);
+       DoAllScriptsFromList (&(G.main->world), event);
+
+       BPY_do_pyscript (&(G.scene->id), event);
        return;
 }
 
@@ -325,3 +341,21 @@ void ReleaseGlobalDictionary (PyObject * dict)
        Py_DECREF (dict);               /* Release dictionary. */
 }
 
+/*****************************************************************************/
+/* Description: This function runs all scripts (if any) present in the       */
+/*              list argument. The event by which the function has been      */
+/*              called, is passed in the event argument.                     */
+/*****************************************************************************/
+void DoAllScriptsFromList (ListBase * list, short event)
+{
+       ID       * id;
+
+       id = list->first;
+
+       while (id != NULL)
+       {
+               BPY_do_pyscript (id, event);
+               id = id->next;
+       }
+}
+