I didn't find a way to set this, even via the right-click menu. Anyone could advise some? Thanks. :)
2 Answers
I didn't see an operator for this either, so you will have to write your own:
import bpy
class ParticleSmoothBrushSelect(bpy.types.Operator):
"""Select the smooth brush"""
bl_idname = "particle.smooth_select"
bl_label = "Select the smooth particle brush"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.context.scene.tool_settings.particle_edit.tool = 'SMOOTH'
return {'FINISHED'}
def register():
bpy.utils.register_class(ParticleSmoothBrushSelect)
def unregister():
bpy.utils.unregister_class(ParticleSmoothBrushSelect)
if __name__ == "__main__":
register()
When run in the text editor, this will register the operator bpy.ops.particle.smooth_select()
. You can assign a shortcut to this operator in the user preferences:
Under Input > 3D view > Particle (assuming you want the hotkey to work in the 3D view when in particle edit mode), press Add New at the bottom of the Particle section.
Collapse the new shortcut labeled "none".
Enter the
bl_idname
into the box.Click the button and press the key(s) on the keyboard you want to set as the shortcut to set the brush type.
One way to keep the operator registered so that you don't need to keep running things in the text editor every time you start blender is by including your operator text datablock in the default .blend and enabling Register in the header (see my answer here for more detailed instructions):
Note that your text datablock must have a .py
extension.
Aside from that, you might just want to make a complete addon.
-
$\begingroup$ Brilliant answer. Thx a lot gandalf3! I bet it will benefit more people. :) Suprising that this feature hasn't been integrated. $\endgroup$ May 4, 2014 at 11:54
I expanded gandalf3's example:
import bpy
items = [
("NONE" , "None" , "Don’t use any brush" , 0),
("COMB" , "Comb" , "Comb hairs" , 1),
("SMOOTH", "Smooth", "Smooth hairs" , 2),
("ADD" , "Add" , "Add hairs" , 3),
("LENGTH", "Length", "Make hairs longer or shorter", 4),
("PUFF" , "Puff" , "Make hairs stand up" , 5),
("CUT" , "Cut" , "Cut hairs" , 6),
("WEIGHT", "Weight", "Weight hair particles" , 7)
]
class PARTICLE_OT_select_brush(bpy.types.Operator):
"""Select a particle brush"""
bl_idname = "particle.select_brush"
bl_label = "Particle Select Brush"
brush = bpy.props.EnumProperty(
name = "brush",
default = "NONE",
items = items
)
def execute(self, context):
context.scene.tool_settings.particle_edit.tool = self.brush
for region in context.area.regions:
if region.type == "TOOLS":
region.tag_redraw()
return {'FINISHED'}
class VIEW3D_MT_particle_edit_select_brush(bpy.types.Menu):
bl_label = "Particle Select Brush"
def draw(self, context):
layout = self.layout
layout.operator_context = "INVOKE_REGION_WIN"
for item in items:
layout.operator(
operator = "particle.select_brush",
text = item[1],
).brush = item[0]
def register():
bpy.utils.register_class(PARTICLE_OT_select_brush)
bpy.utils.register_class(VIEW3D_MT_particle_edit_select_brush)
def unregister():
bpy.utils.unregister_class(VIEW3D_MT_particle_edit_select_brush)
bpy.utils.unregister_class(PARTICLE_OT_select_brush)
if __name__ == "__main__":
register()
#register keys via script
#might be better done via user preferences
#see image below
wm = bpy.context.window_manager
km = wm.keyconfigs['Blender User'].keymaps['Particle']
keys = ("ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT")
for item, key in zip(items, keys):
kmi = km.keymap_items.new(
idname = "particle.select_brush",
type = key,
value = "PRESS",
)
kmi.properties.brush = item[0]
kmi = km.keymap_items.new(
idname = "wm.call_menu",
type = "TAB",
value = "PRESS",
ctrl = True
)
kmi.properties.name = "VIEW3D_MT_particle_edit_select_brush"
You can bind keys to call a menu or directly choose a specific brush.