# Can't remove object via python once grouped

I'm writing a script that is adding and removing about 50 objects every frame. That part is working fine, but once I add the objects to a group, it creates odd errors.

In tracking down the error, I simplified my project and ran into the same issue

I could understand if the group were one of the users of the object, but the object.users count doesn't increase when grouped.

Try it yourself:

import bpy

scn = bpy.data.scenes['Scene']
ob = bpy.data.objects['Cube']

bpy.data.objects.remove(ob)


works fine, but:

import bpy

scn = bpy.data.scenes['Scene']
ob = bpy.data.objects['Cube']

testgroup = bpy.data.groups.new('testgroup')

bpy.data.objects.remove(ob)


throws the following error:

RuntimeError: Error: Object 'Cube' must have zero users to be removed, found 1


What's going on? Am I missing something, or do I need to file a bug report?

• yes it could be a bug, tested after adding user_clear() and got the same result, please add your blender version ( mine is 2.77 a ) – Chebhou May 5 '16 at 22:26
• Same, I'm on 2.77a – Sterling Roth May 5 '16 at 22:33
• try it on older version if you have one or wait for some to do ( to make sure it's ) – Chebhou May 5 '16 at 22:37

So, I submitted a bug report, and got a same day response from Bastien. Turns out, the problem is related to the Fake User restructuring that is going on and there isn't a straightforward way to do it. Here's a link to the bug report: Blender Bug Tracker

He also pointed me in the direction of an effective workaround that I thought I'd share. Here is the working code:

import bpy

scn = bpy.data.scenes['Scene']
ob = bpy.data.objects['Cube']

testgroup = bpy.data.groups.new('testgroup')

• This results in the following error: AttributeError: 'bpy_prop_collection' object has no attribute 'objects' – Školstvo May 24 '17 at 6:56