[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25887] trunk/blender: rna/py api

Campbell Barton ideasman42 at gmail.com
Mon Jan 11 01:41:31 CET 2010


Revision: 25887
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25887
Author:   campbellbarton
Date:     2010-01-11 01:41:31 +0100 (Mon, 11 Jan 2010)

Log Message:
-----------
rna/py api
bpy.data.scenes.remove(scene) # now works without crashing
bpy.data.texts.new(name)/remove(text)/load(path) # added

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_info.py
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c

Modified: trunk/blender/release/scripts/ui/space_info.py
===================================================================
--- trunk/blender/release/scripts/ui/space_info.py	2010-01-10 23:18:09 UTC (rev 25886)
+++ trunk/blender/release/scripts/ui/space_info.py	2010-01-11 00:41:31 UTC (rev 25887)
@@ -384,12 +384,10 @@
 
             op_strings.append('')
 
-        bpy.ops.text.new() # XXX - assumes new text is always at the end!
-        textblock = bpy.data.texts[-1]
+        textblock = bpy.data.texts.new("OperatorList.txt")
         textblock.write('# %d Operators\n\n' % tot)
         textblock.write('\n'.join(op_strings))
-        textblock.name = "OperatorList.txt"
-        print("See OperatorList.txt textblock")
+        self.report({'INFO'}, "See OperatorList.txt textblock")
         return {'FINISHED'}
 
 bpy.types.register(HELP_OT_manual)

Modified: trunk/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_types.h	2010-01-10 23:18:09 UTC (rev 25886)
+++ trunk/blender/source/blender/makesrna/RNA_types.h	2010-01-11 00:41:31 UTC (rev 25887)
@@ -332,6 +332,7 @@
 #define MainMeshes Main
 #define MainLamps Main
 #define MainObjects Main
+#define MainTexts Main
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/makesrna/intern/rna_main_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-01-10 23:18:09 UTC (rev 25886)
+++ trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-01-11 00:41:31 UTC (rev 25887)
@@ -33,6 +33,8 @@
 #include "RNA_types.h"
 #include "RNA_enum_types.h"
 
+#include "BKE_utildefines.h"
+
 #ifdef RNA_RUNTIME
 
 #include "BKE_main.h"
@@ -44,6 +46,7 @@
 #include "BKE_image.h"
 #include "BKE_texture.h"
 #include "BKE_scene.h"
+#include "BKE_text.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
@@ -51,7 +54,10 @@
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
+#include "DNA_text_types.h"
 
+#include "ED_screen.h"
+
 Tex *rna_Main_add_texture(Main *bmain, char *name)
 {
 	return add_texture(name);
@@ -82,9 +88,23 @@
 {
 	return add_scene(name);
 }
-void rna_Main_scenes_remove(Main *bmain, ReportList *reports, struct Scene *scene)
+void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, struct Scene *scene)
 {
-	free_libblock(&bmain->scene, scene);
+	/* dont call free_libblock(...) directly */
+	Scene *newscene;
+
+	if(scene->id.prev)
+		newscene= scene->id.prev;
+	else if(scene->id.next)
+		newscene= scene->id.next;
+	else {
+		BKE_reportf(reports, RPT_ERROR, "Scene \"%s\" is the last, cant ve removed.", scene->id.name+2);
+		return;
+	}
+
+	ED_screen_set_scene(C, newscene);
+
+	unlink_scene(bmain, scene, newscene);
 }
 
 Object *rna_Main_objects_new(Main *bmain, char* name, int type)
@@ -159,6 +179,25 @@
 	/* XXX python now has invalid pointer? */
 }
 
+Text *rna_Main_texts_new(Main *bmain, char* name)
+{
+	return add_empty_text(name);
+}
+void rna_Main_texts_remove(Main *bmain, ReportList *reports, Text *text)
+{
+	unlink_text(bmain, text);
+	free_libblock(&bmain->text, text);
+	/* XXX python now has invalid pointer? */
+}
+Text *rna_Main_texts_load(Main *bmain, ReportList *reports, char* path)
+{
+	Text *txt= add_text(path, bmain->name);
+	if(txt==NULL)
+		BKE_reportf(reports, RPT_ERROR, "Couldn't load text from path \"%s\".", path);
+
+	return txt;
+}
+
 bArmature *rna_Main_armatures_new(Main *bmain, char* name)
 {
 	bArmature *arm= add_armature(name);
@@ -241,7 +280,7 @@
 	RNA_def_function_return(func, parm);
 
 	func= RNA_def_function(srna, "remove", "rna_Main_scenes_remove");
-	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
 	parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 	RNA_def_function_ui_description(func, "Remove a scene from the current blendfile.");
@@ -256,7 +295,6 @@
 
 	RNA_def_property_srna(cprop, "MainObjects");
 	srna= RNA_def_struct(brna, "MainObjects", NULL);
-//	RNA_def_struct_sdna(srna, "Object");
 	RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_objects_new");
@@ -285,7 +323,6 @@
 
 	RNA_def_property_srna(cprop, "MainMaterials");
 	srna= RNA_def_struct(brna, "MainMaterials", NULL);
-//	RNA_def_struct_sdna(srna, "Material");
 	RNA_def_struct_ui_text(srna, "Main Material", "Collection of materials.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_materials_new");
@@ -314,7 +351,6 @@
 
 	RNA_def_property_srna(cprop, "MainMeshes");
 	srna= RNA_def_struct(brna, "MainMeshes", NULL);
-//	RNA_def_struct_sdna(srna, "Mesh");
 	RNA_def_struct_ui_text(srna, "Main Meshes", "Collection of meshes.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_meshes_new");
@@ -339,7 +375,6 @@
 
 	RNA_def_property_srna(cprop, "MainLamps");
 	srna= RNA_def_struct(brna, "MainLamps", NULL);
-//	RNA_def_struct_sdna(srna, "Lamp");
 	RNA_def_struct_ui_text(srna, "Main Lamps", "Collection of lamps.");
 
 	func= RNA_def_function(srna, "new", "rna_Main_lamps_new");
@@ -406,7 +441,37 @@
 }
 void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop)
 {
+	StructRNA *srna;
+	FunctionRNA *func;
+	PropertyRNA *parm;
 
+	RNA_def_property_srna(cprop, "MainTexts");
+	srna= RNA_def_struct(brna, "MainTexts", NULL);
+	RNA_def_struct_ui_text(srna, "Main Texts", "Collection of texts.");
+
+	func= RNA_def_function(srna, "new", "rna_Main_texts_new");
+	RNA_def_function_ui_description(func, "Add a new text to the main database");
+	parm= RNA_def_string(func, "name", "Text", 0, "", "New name for the datablock.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	/* return type */
+	parm= RNA_def_pointer(func, "text", "Text", "", "New text datablock.");
+	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "remove", "rna_Main_texts_remove");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Remove a text from the current blendfile.");
+	parm= RNA_def_pointer(func, "text", "Text", "", "Text to remove.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+
+	/* load func */
+	func= RNA_def_function(srna, "load", "rna_Main_texts_load");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Add a new text to the main database from a file");
+	parm= RNA_def_string(func, "path", "Path", FILE_MAXDIR + FILE_MAXFILE, "", "path for the datablock.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	/* return type */
+	parm= RNA_def_pointer(func, "text", "Text", "", "New text datablock.");
+	RNA_def_function_return(func, parm);
 }
 void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop)
 {





More information about the Bf-blender-cvs mailing list