I want to delete object hierarchy from 3DView but I can not find any keybindings for this. In outliner is this possible but not in 3DView so I wrote a simple script and wanted to execute it when pressing for example the delete key.
How can I do this?
Here the script (maybe somebody have an idea?)
import bpy
objs = bpy.context.selected_objects
delobj = bpy.ops.object.select_grouped(type='CHILDREN_RECURSIVE')
bpy.ops.object.delete({"selected_objects": objs})
bpy.ops.object.delete({"selected_objects": delobj})
Thanks!
UPDATE: This part was added as an answer. I've moved it to the question so that people without sufficient privilege to see deleted answers can respond:
I get a menu but it does nothing also the key binding is not visible in the preferences. I'm very new to blender programming so it would be great when you could check my code.
Thanks!
import bpy
class DeleteHierarchy(bpy.types.Operator):
"""Delete objects with children"""
bl_idname = "view3d.delete_hier"
bl_label = "Delete"
def delete_hierarchy(self):
parent = bpy.context.selected_objects
child = bpy.ops.object.select_grouped(type='CHILDREN_RECURSIVE')
bpy.ops.object.delete({"selected_objects": parent})
bpy.ops.object.delete({"selected_objects": child})
key_config = bpy.context.window_manager.keyconfigs.addon
if key_config:
key_map = key_config.kexmaps.new(name='3D View', space_type='VIEW_3D')
key_entry = key_map.keymap_items.new(DeleteHierarchy.bl_idname, type='X', value='PRESS', ctrl=True)
# delete_hierarchy(self)
def menu_func(self, context):
self.layout.operator(DeleteHierarchy.bl_idname, text="Delete")
def register():
bpy.utils.register_class(DeleteHierarchy)
bpy.types.VIEW3D_MT_view.append(menu_func)
def unregister():
bpy.utils.unregister_class(DeleteHierarchy)
bpy.types.VIEW3D_MT_view.remove(menu_func)
if __name__ == "__main__":
register()
```