5
$\begingroup$

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']

scn.objects.unlink(ob)
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')
testgroup.objects.link(ob)
testgroup.objects.unlink(ob)

scn.objects.unlink(ob)
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?

$\endgroup$
  • 1
    $\begingroup$ 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 ) $\endgroup$ – Chebhou May 5 '16 at 22:26
  • 1
    $\begingroup$ Same, I'm on 2.77a $\endgroup$ – Sterling Roth May 5 '16 at 22:33
  • $\begingroup$ try it on older version if you have one or wait for some to do ( to make sure it's ) $\endgroup$ – Chebhou May 5 '16 at 22:37
3
$\begingroup$

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')
testgroup.objects.link(ob)
testgroup.objects.unlink(ob)

scn.objects.unlink(ob)

ob.user_clear()    #manually clears all users, frees the object to be removed

bpy.data.objects.remove(ob)
$\endgroup$
  • $\begingroup$ I have tried that see my comment and got the same error $\endgroup$ – Chebhou May 6 '16 at 20:55
  • $\begingroup$ This results in the following error: AttributeError: 'bpy_prop_collection' object has no attribute 'objects' $\endgroup$ – Školstvo May 24 '17 at 6:56
1
$\begingroup$

No you don't appear to be missing anything. I just tested it here with versions from 2.70 to 2.76 and they do not show this error, so it is a regression introduced in 2.77.

You should report it as a bug at developer.blender.org

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.