How can I delete hierarchy of objects in code? When trying to delete the "parent_obj", it's written in the GUI tooltip:
bpy.ops.outliner.object_operation(type='DELETE_HIERARCHY')
I tried to select the "parent_obj" using this code:
context.scene.objects.active = bpy.data.objects['parent_obj']
But got this error:
File "~/blender-2.76-rc2-linux-glibc211-x86_64/2.76/scripts/modules/bpy/ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.outliner.object_operation.poll() failed, context is incorrect
Edit
Ok, I've found how to bypass this problem. Instead of using bpy.ops.outliner.object_operation(), I first select the objects hierarchy, and then used bpy.ops.object.delete():
bpy.data.objects[obj_name].select = True
for child in bpy.data.objects[obj_name].children:
child.select = True
bpy.ops.object.delete()