Assuming you're using >v2.8, this should work.
Very basic and there might be a better way, (almost certainly!!) but it works.
After you run this, a new menu item should show up in your "Select" menu. Right click this item and assign a shortcut as normal.
## Read the comments for a very basic explanation of what the various parts do
bl_info = { ## stuff so Blender can find your code
"name": "My Addon",
"author": "Your Name",
"version": (0, 1),
"blender": (2, 90, 0),
"location": "View3D > Select",
"description": "Your addon descriptioin",
"warning": "",
"wiki_url": "",
"category": "3D View",
}
import bpy
from bpy.types import Operator
class MYADDON_OT_My_Class(Operator): ## stuff to be able to make a menu item
bl_idname = "object.my_class"
bl_label = "Test"
bl_description = "My Description"
bl_space_type = "VIEW_3D"
bl_region_type = 'UI'
def invoke(self, context, event):
## the main event, this will be ran when your button is pressed
bpy.ops.object.select_pattern(pattern="Cube?")
bpy.ops.object.select_pattern(pattern="Sphere?")
return {'FINISHED'}
def menu_func(self, context): ## creating the menu item
self.layout.operator(MYADDON_OT_My_Class.bl_idname, icon='MESH_CUBE')
def register(): ## register the functions so Blender can use them
bpy.utils.register_class(MYADDON_OT_My_Class)
bpy.types.VIEW3D_MT_select_object.append(menu_func)
def unregister(): ## unregister when the addon is removed later
bpy.utils.unregister_class(MYADDON_OT_My_Class)
bpy.types.VIEW3D_MT_select_object.remove(menu_func)
if name == "main":
register()
pattern="Cube?*"and usingextend=Trueto extend the selection. – batFINGER Nov 09 '20 at 14:27