Here is an add-on script that creates a mask from the face set under the mouse pointer on a single key press. Shortcut key is Y. The menu entry is located under View3D > Mask > Mask From Face Set in Sculpt mode.
The operator is only four lines but for the shortcut key, a few more lines are required.
bl_info = {
"name": "Mask From Face Set",
"description": "Creates a mask from the face set under the mouse.",
"author": "Blunder",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Mask > Mask From Face Set",
"support": "COMMUNITY",
"category": "Sculpt",
}
import bpy
class MaskFromFaceSetOperator(bpy.types.Operator):
bl_idname = "wm.mask_from_face_set"
bl_label = "Mask From Face Set Operator"
def execute(self, context):
bpy.ops.paint.mask_flood_fill(mode='VALUE', value=0)
bpy.ops.sculpt.face_set_change_visibility(mode='TOGGLE')
bpy.ops.paint.mask_flood_fill(mode='INVERT')
bpy.ops.sculpt.face_set_change_visibility(mode='SHOW_ALL')
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu.
def menu_func(self, context):
self.layout.operator(MaskFromFaceSetOperator.bl_idname, text="Mask From Face Set")
# store keymaps here to access after registration
addon_keymaps = []
# Register and add to the mask menu (required to also use F3 search "Mask From Face Set Operator" for quick access).
def register():
bpy.utils.register_class(MaskFromFaceSetOperator)
bpy.types.VIEW3D_MT_mask.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
# Note that in background mode (no GUI available), keyconfigs are not available either,
# so we have to check this to avoid nasty errors in background case.
kc = wm.keyconfigs.addon
if kc:
km = wm.keyconfigs.addon.keymaps.new(name='Sculpt', space_type='EMPTY')
kmi = km.keymap_items.new(MaskFromFaceSetOperator.bl_idname, 'Y', 'PRESS', ctrl=False, shift=False)
addon_keymaps.append((km, kmi))
def unregister():
# handle the keymap
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
bpy.utils.unregister_class(MaskFromFaceSetOperator)
bpy.types.VIEW3D_MT_mask.remove(menu_func)
if __name__ == "__main__":
register()