diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-06-24 23:23:34 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-06-24 23:23:34 +0400 |
commit | 3f2fef55c2bbeb1f837b48c76263e3e035d56792 (patch) | |
tree | 49b7dd1f984f2e816ff22e6d3f09a74680f83746 /source/blender/makesrna/intern/rna_main_api.c | |
parent | d2a5bbdc2c04973f5a9e65003f70cbe336b87ad0 (diff) |
- added API functions:
* Main.remove_object
* Scene.add_object
* Scene.remove_object
* Object.convert_to_triface
* Object.create_preview_mesh
- a small tweak in set_mesh (blenkernel/inter/mesh.c) to make it work on objects having data == NULL
Diffstat (limited to 'source/blender/makesrna/intern/rna_main_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 2c78884a027..08a3b7cee25 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -62,7 +62,29 @@ static void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me) static Object* rna_Main_add_object(Main *main, int type, char *name) { - return add_only_object(type, name); + Object *ob= add_only_object(type, name); + ob->id.us--; + return ob; +} + +/* + WARNING: the following example shows when this function should not be called + + ob = bpy.data.add_object() + scene.add_object(ob) + + # ob is freed here + scene.remove_object(ob) + + # don't do this since ob is already freed! + bpy.data.remove_object(ob) +*/ +static void rna_Main_remove_object(Main *main, ReportList *reports, Object *ob) +{ + if(ob->id.us == 0) + free_libblock(&main->object, ob); + else + BKE_report(reports, RPT_ERROR, "Object must have zero users to be removed."); } #else @@ -89,13 +111,19 @@ void RNA_api_main(StructRNA *srna) func= RNA_def_function(srna, "add_object", "rna_Main_add_object"); RNA_def_function_ui_description(func, "Add a new object."); - parm= RNA_def_enum(func, "type", object_type_items, 0, "Type", "Type of Object."); + parm= RNA_def_enum(func, "type", object_type_items, 0, "", "Type of Object."); RNA_def_property_flag(parm, PROP_REQUIRED); parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); parm= RNA_def_pointer(func, "object", "Object", "", "New object."); RNA_def_function_return(func, parm); + func= RNA_def_function(srna, "remove_object", "rna_Main_remove_object"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove an object if it has zero users."); + parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "add_mesh", "rna_Main_add_mesh"); RNA_def_function_ui_description(func, "Add a new mesh."); parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock."); @@ -108,7 +136,6 @@ void RNA_api_main(StructRNA *srna) RNA_def_function_ui_description(func, "Remove a mesh if it has zero users."); parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); - } #endif |