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/blenkernel/intern/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/blenkernel/intern/group.c')
-rw-r--r--source/blender/blenkernel/intern/group.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 6bb47bc0f0f..77bf5859385 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -95,7 +95,7 @@ void unlink_group(Group *group)
/* ensure objects are not in this group */
for(; base; base= base->next) {
- if(rem_from_group(group, base->object) && find_group(base->object, NULL)==NULL) {
+ if(rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL)==NULL) {
base->object->flag &= ~OB_FROMGROUP;
base->flag &= ~OB_FROMGROUP;
}
@@ -153,15 +153,15 @@ Group *copy_group(Group *group)
}
/* external */
-void add_to_group(Group *group, Object *ob)
+static int add_to_group_internal(Group *group, Object *ob)
{
GroupObject *go;
- if(group==NULL || ob==NULL) return;
+ if(group==NULL || ob==NULL) return 0;
/* check if the object has been added already */
for(go= group->gobject.first; go; go= go->next) {
- if(go->ob==ob) return;
+ if(go->ob==ob) return 0;
}
go= MEM_callocN(sizeof(GroupObject), "groupobject");
@@ -169,10 +169,31 @@ void add_to_group(Group *group, Object *ob)
go->ob= ob;
+ return 1;
+}
+
+int add_to_group(Group *group, Object *object, Scene *scene, Base *base)
+{
+ if(add_to_group_internal(group, object)) {
+ if((object->flag & OB_FROMGROUP)==0) {
+
+ if(scene && base==NULL)
+ base= object_in_scene(object, scene);
+
+ object->flag |= OB_FROMGROUP;
+
+ if(base)
+ base->flag |= OB_FROMGROUP;
+ }
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
/* also used for ob==NULL */
-int rem_from_group(Group *group, Object *ob)
+static int rem_from_group_internal(Group *group, Object *ob)
{
GroupObject *go, *gon;
int removed = 0;
@@ -192,6 +213,26 @@ int rem_from_group(Group *group, Object *ob)
return removed;
}
+int rem_from_group(Group *group, Object *object, Scene *scene, Base *base)
+{
+ if(rem_from_group_internal(group, object)) {
+
+ if(find_group(object, NULL) == NULL) {
+ if(scene && base==NULL)
+ base= object_in_scene(object, scene);
+
+ object->flag &= ~OB_FROMGROUP;
+
+ if(base)
+ base->flag &= ~OB_FROMGROUP;
+ }
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
int object_in_group(Object *ob, Group *group)
{
GroupObject *go;