1

Is there a way to automatically delete children when the parent is deleted? By automatically I mean that you don't do any selection (or other action) of the children prior to selecting and deleting the parent.

I can make a method that select and delete the children. But I'm not sure how to call this prior to the bpy.ops.object.delete() operator. Maybe some custom property of the objects with some clever update? Or maybe a handle?

EDIT: I tried to override the delete operator like this:

class MYOP_OT_delete_family(bpy.types.Operator):
bl_idname = "object.delete"
bl_label = "Delete parent, children and sibling"
bl_options = {'REGISTER', 'UNDO'} # Must have REGISTER!   

def execute(self, context):

    top_object = context.object

    if top_object.parent is not None:
        top_object = top_object.parent

    top_object.select_set(True)
    for child in top_object.children:
        child.select_set(True)

    bpy.ops.object.delete() # BUT THIS IS NOW OVERRIDDEN!!!

    return {'FINISHED'}

This breaks Blender when I delete something. This is not surprising, since I both rely on and override the bpy.ops.delete operator. I suppose that I can make this as a new operator (bpy.ops.delete_family as the class name) and then keymap to this operator. But I would prefer not to have to do these manual setup things and truely override the default delete operator.

DrDress
  • 563
  • 4
  • 19
  • 3
    https://blender.stackexchange.com/questions/101520/how-can-i-disable-edit-source-at-my-ui – batFINGER Dec 18 '20 at 14:53
  • Or just override the context: https://blender.stackexchange.com/a/27235 ? – brockmann Dec 18 '20 at 15:15
  • Always obtuse. Script shows how to select parent and siblings recursively (calls itself) and endlessly select and select...never-bloody-endingly... Suggest Look for an API method to remove objects. Look for a way to select hierarchy https://blender.stackexchange.com/questions/145620/looping-over-hierarchies-of-objects-with-python – batFINGER Dec 21 '20 at 11:44
  • 1
    @batFINGER. That was kinda rude. I'm trying as good as I can to clarify what I want to do, which is difficult since I don't understand the entire API. But your idea for overriding the delete operator is really good and something I haven't seen any other place where people asked about this topic. It actually works pretty well now. – DrDress Dec 21 '20 at 15:01

0 Answers0