Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-11-11 19:28:53 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-11-11 19:28:53 +0300
commitbc6190f3e370d21aff0bd9d96fd43d92382c6466 (patch)
tree94bdbadbeb908085e86fd73b447df1ec1ed05858 /source/blender/makesrna/intern/rna_group.c
parentf24392805515416bdba35f531457183e67ef274c (diff)
python api for collection add()/remove()
Added a group example C = bpy.context ob = C.active_object bpy.data.groups[0].objects.add(ob) - add_to_group and rem_from_group now take optional scene and base flags and deal with updating the object & base flags - operators that add objects to groups were setting ob->recalc= OB_RECALC_OB; looks like its not needed. - previously add() ignored python args, now add and remove are called like any other FunctionRNA from python. - made the pyrna api use tp_getset's for collestions active/add()/remove()
Diffstat (limited to 'source/blender/makesrna/intern/rna_group.c')
-rw-r--r--source/blender/makesrna/intern/rna_group.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c
index dddc2062f07..8f6a5f1005c 100644
--- a/source/blender/makesrna/intern/rna_group.c
+++ b/source/blender/makesrna/intern/rna_group.c
@@ -33,6 +33,11 @@
#ifdef RNA_RUNTIME
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_group.h"
+
static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter)
{
ListBaseIterator *internal= iter->internal;
@@ -41,6 +46,16 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter)
return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject*)internal->link)->ob);
}
+static int rna_Group_objects_add(Group *group, bContext *C, Object *object)
+{
+ return add_to_group(group, object, CTX_data_scene(C), NULL);
+}
+
+static int rna_Group_objects_remove(Group *group, bContext *C, Object *object)
+{
+ return rem_from_group(group, object, CTX_data_scene(C), NULL);
+}
+
#else
void RNA_def_group(BlenderRNA *brna)
@@ -57,16 +72,41 @@ void RNA_def_group(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the center to use when instancing as DupliGroup.");
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
+ prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER);
+ RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
+ RNA_def_property_array(prop, 20);
+ RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli.");
+
+
+ /* add object */
+ FunctionRNA *func;
+ PropertyRNA *parm;
+ func= RNA_def_function(srna, "add_object", "rna_Group_objects_add");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func, "Add this object to a group");
+ /* return type */
+ parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target.");
+ RNA_def_function_return(func, parm);
+ /* object to add */
+ parm= RNA_def_pointer(func, "object", "Object", "", "Object to add.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
+ /* remove object */
+ func= RNA_def_function(srna, "remove_object", "rna_Group_objects_remove");
+ RNA_def_function_ui_description(func, "Remove this object to a group");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ /* return type */
+ parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target.");
+ RNA_def_function_return(func, parm);
+ /* object to remove */
+ parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects.");
- RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, 0, 0);
-
- prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER);
- RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli.");
+ RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, "add_object", "remove_object");
}
#endif