2
$\begingroup$

Somehow I have managed to add objects to a group called "myGroup" without actually wanting to do that. I now want to remove all those objects from that group, which at the same time were already assigned to another group. I figured the best way would be to do that in python. I tried the following:

allObjects = bpy.data.objects;
for obj in allObjects:
    count = 0;
    found = 0;
    for gr in obj.users_group:
        count = count + 1;
        if gr.name == 'myGroup'
            found = 1;
    if count > 1 and found == 1
        for object in bpy.context.visible_objects:
            object.select = False;
        obj.select = True;
        REMOVE obj from group myGroup!!!!

I do not know how to put the last line into valid python code. I know that there is a function could "bpy.ops.object.group_remove()", but I do not understand which group the object is deleted from when I call this function. Any help? :)

$\endgroup$

1 Answer 1

3
$\begingroup$

If you don't mind not using python, you can just select the objects and press ⎈ Ctrl⎇ AltG, then select the group you want to remove them from:

enter image description here


If you still want to use python, then you want a group operator, rather than a object operator:

bpy.ops.group.objects_remove(group="myGroup")

This will remove the selected objects from the group "myGroup".

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .