How would I go about creating a hotkey that would operate as follows?:
- With an object selected in the modeling viewport:
- Press Shift + D (this would be the custom shortcut to trigger what follows ,not the default 'duplicate' command)
Selected Object gets a catmull-clark subdiv modifier added with default settings
bpy.ops.object.modifier_add(type='SUBSURF')
Subdivision modifier gets applied to mesh (
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subdivision")
?
I am new to Blender as of 2.8 and am interested in customizing the UI to make it more like the software packages I am coming from (Maya and Modo). At the moment I am interested in understanding how to consolidate multiple commands into a single operation that can be bound to a hotkey. I figured this would be a simple enough one to start with. I have some limited python experience from Maya and have been looking at the API but I have been having difficulty understanding how it all works. I understand I would likely need a hotkey .py file to bind the operation to a key and an operator .py file to define the operations and possibly to include the commands. How would I get this working?
I tried a hotkey file in startup that looked like this:
import bpy
import os
km = kc.keymaps.new('Window', space_type='EMPTY', region_type='WINDOW', modal=False)
Global_Keys()
kmi = km.keymap_items.new('mesh.testSubdivide', 'D', 'PRESS', shift=True)
With an operator .py file that looked like this:
class testSubdivide(bpy.types.Operator):
bl_idname = "mesh.testSubdivide"
bl_label = "testSubdivide"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subdivision")
return {'FINISHED'}
I know this is wrong...but i'm blocked. How would I do this?