1
$\begingroup$

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.

$\endgroup$
4
  • 3
    $\begingroup$ blender.stackexchange.com/questions/101520/… $\endgroup$
    – batFINGER
    Dec 18, 2020 at 14:53
  • $\begingroup$ Or just override the context: blender.stackexchange.com/a/27235 ? $\endgroup$
    – brockmann
    Dec 18, 2020 at 15:15
  • $\begingroup$ 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 blender.stackexchange.com/questions/145620/… $\endgroup$
    – batFINGER
    Dec 21, 2020 at 11:44
  • 1
    $\begingroup$ @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. $\endgroup$
    – DrDress
    Dec 21, 2020 at 15:01

0

You must log in to answer this question.

Browse other questions tagged .