Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Blender add-on to allow deleting any mesh component without questions asked.
# 2015.10
# 2020.6
# 2021.1 - Sami S.
# License:
# This script is “free as in beer” i.e.
# feel free to use this script in Blender any way you like.
# However, do not re-distribute the script - share a link to my page instead!
# How to install:
# Copy this file's content into some file with .py suffix.
# In Blender, open Preferences (Shift + P)
# Select Add-ons tab
# Press 'Install...'
# Browse to and select this file
# Press 'Install Add-on' button
# Press 'Community' filter button
# Check 'Delete Any Components' to enable the add-on
# How to add a keyboard shortcut:
# NOTE: DO THIS ONLY IF automatic adding of
# keyboard shortcut is disabled in script file below!
# Go to Preferences (Shift + P)
# Go to Keymap tab and browse to > 3D View > 3D View (Global) >
# Scroll to the end of this folder and press '+ Add a new entry' button
# Fill/paste the following string to the "Identifier of Operator" field: object.ss_delete_any_components
# Assign a key (Delete), operation (Press) and modifier key(s) (Shift)
# Save preferences: Bottom left hamburger icon > Save Preferences
# Script is ready for use!
# How to use:
# Use script in 3D View / mesh edit mode to delete a selection of any component type
# Select components and press the shortcut key
# NOTE: does not work in multi-component select mode
import bpy
import rna_keymap_ui
from bpy.types import Operator
bl_info = {
"name": "Delete Any Components",
"author": "Sami S.",
"version": (1, 1),
"blender": (2, 80, 0),
"location": "Mesh Edit mode, Shift + Delete",
"description": "Indiscriminately delete any selected mesh components",
"category": "Object"
}
class OBJECT_OT_delete_any_component(bpy.types.Operator):
bl_idname = "object.ss_delete_any_components"
bl_label = "Delete Any Components"
# bl_options = {"UNDO"}
# invoke
def execute(self, context):
if bpy.context.selected_objects.count != 0 and bpy.context.object.type == 'MESH':
if bpy.context.mode == 'EDIT_MESH':
#Get edit_mode
em = bpy.context.tool_settings.mesh_select_mode[:]
# Vertex mode
if em == (True, False, False):
bpy.ops.mesh.delete(type='VERT')
# Edge mode
if em == (False, True, False):
bpy.ops.mesh.delete(type='EDGE')
# Face mode
if em == (False, False, True):
bpy.ops.mesh.delete(type='FACE')
return {"FINISHED"}
# Registration
addon_keymaps = []
def register():
bpy.utils.register_class(OBJECT_OT_delete_any_component)
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new("object.ss_delete_any_components", type='DEL', value='PRESS', shift=True)
addon_keymaps.append((km, kmi))
def unregister():
bpy.utils.unregister_class(OBJECT_OT_delete_any_component)
for km,kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment