6
$\begingroup$

I'm not very experienced with scripting but was hoping to be able to find out what mesh selection mode (edges,faces or verts) Blender is in while in edit mode to make some custom hotkey assignments that takes this into account.

I have worked out how to set up a basic modal operator so need something to feed into an if statement.

Thanks

$\endgroup$
5
$\begingroup$

You can access this via the Scene property:

Or if you're editing meshes using the BMesh API (if you're modifying the mesh in BMesh already).


Example to run in the console:

>>> print(bpy.context.scene.tool_settings.mesh_select_mode)
<bpy_boolean[3], ToolSettings.mesh_select_mode>

To see the values, you can get get the sequence as a tuple

>>> print(tuple(bpy.context.scene.tool_settings.mesh_select_mode))
(True, False, False)
$\endgroup$
0
$\begingroup$

It took a newbie like me a little bit to figure out the if statement: hope this helps.

    def invoke(self, context, event):
        if tuple(bpy.context.scene.tool_settings.mesh_select_mode) == (True, False, False):
            bpy.ops.mesh.bevel('INVOKE_DEFAULT',vertex_only=True)
        else:
            bpy.ops.mesh.bevel('INVOKE_DEFAULT',vertex_only=False)
        return {'FINISHED'}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.