Skip to content

PLUGIN: Global - Mode switching can accidentally make OP fail #25

Description

@Danweel

=needs more testing=

highlights3, frames1, frames2, op14, op8, op12:

has:

bpy.ops.object.mode_set(mode='PAINT_GPENCIL')
# ... do stuff ...
bpy.ops.object.mode_set(mode='EDIT_GPENCIL') _# sometimes_

In THEORY, if you accidentally leave the object in the wrong mode, the next operator might fail. We'll want to test this and see, but in terms of best practices something safer would be to define

def _ensure_mode(context: bpy.types.Context, mode: str) -> None:
    """Switches to the desired mode if not already there."""
    if context.object.mode != mode:
        bpy.ops.object.mode_set(mode=mode)

# Usage:
_ensure_mode(context, 'PAINT_GPENCIL')

Something like that =TEST THIS=

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C issueC-class issues don't explicitly prevent actions from being performed.MildLow Severity issues that only causes light visible issues or inconvenience within its class.more testing neededThis issue needs more people to test its parameters, scope or repeatability.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions