Skip to content

command

undo_chunk(name='')

Context manager to wrap multiple actions into a single undo chunk.

The name of the undo chunk can either be given when entering the block, or updated later using the nuke.Undo.name(name) method.

Parameters:

Name Type Description Default
name str

Name of the undo chunk.

''

Examples:

As a context manager:

>>> with undo_chunk("Load Image"):
>>>    # do multiple actions here
>>>    ...

As a decorator:

>>> @undo_chunk("Load Image")
>>> def load_image():
>>>    # do multiple actions here
>>>    ...
Source code in client/ayon_nuke/api/command.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@contextlib.contextmanager
def undo_chunk(name: str = ""):
    """Context manager to wrap multiple actions into a single undo chunk.

    The name of the undo chunk can either be given when entering the block,
    or updated later using the `nuke.Undo.name(name)` method.

    Args:
        name (str): Name of the undo chunk.

    Examples:
        As a context manager:
        >>> with undo_chunk("Load Image"):
        >>>    # do multiple actions here
        >>>    ...

        As a decorator:
        >>> @undo_chunk("Load Image")
        >>> def load_image():
        >>>    # do multiple actions here
        >>>    ...

    """
    nuke.Undo.begin()
    if name:
        nuke.Undo.name(name)

    try:
        yield
    finally:
        nuke.Undo.end()

viewer_update_and_undo_stop()

Lock viewer from updating and stop recording undo steps

Source code in client/ayon_nuke/api/command.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
@contextlib.contextmanager
def viewer_update_and_undo_stop():
    """Lock viewer from updating and stop recording undo steps"""
    try:
        # stop active viewer to update any change
        viewer = nuke.activeViewer()
        if viewer:
            viewer.stop()
        else:
            log.warning("No available active Viewer")
        nuke.Undo.disable()
        yield
    finally:
        nuke.Undo.enable()