Skip to content

example

Example nodes and extension.

Basic2IntegerAddition

Bases: WorkflowNode

Add two integers together.

Source code in client/ayon_workflow/plugin_system/example.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Basic2IntegerAddition(WorkflowNode):
    """ Add two integers together.
    """
    version: str = "0.0.1"
    inputs = {
        "a": {
            "description": "The first integer to add.",
        },
        "b": {
            "description": "Optional second integer to add.",
        },
    }
    outputs = {
        "result": {
            "description": "The result of the addition.",
        },
    }

    def execute(self, a: int, b: Optional[int] = 5) -> int:
        """ Add two integers together.
        """
        b = b or 0
        return a + b

execute(a, b=5)

Add two integers together.

Source code in client/ayon_workflow/plugin_system/example.py
30
31
32
33
34
def execute(self, a: int, b: Optional[int] = 5) -> int:
    """ Add two integers together.
    """
    b = b or 0
    return a + b

CreateAnEmptyFile

Bases: WorkflowNode

Creates an empty file at the specified path. Delete on revert.

Source code in client/ayon_workflow/plugin_system/example.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class CreateAnEmptyFile(WorkflowNode):
    """ Creates an empty file at the specified path.
        Delete on revert.
    """
    version: str = "0.0.1"
    inputs = {
        "path": {
            "description": "The path to the file to create.",
            "widget": {
                "name": "filepath",
                "caption": "Select any file",
                "filter": "All Files (*.*)",
            },
        }
    }
    outputs = {
        "output_path": {
            "description": "The path to the created file.",
        },
    }

    def execute(self, path: str) -> str:
        """ Creates an empty file at the specified path.
        """
        with open(path, "w") as f:
            f.write("")
        return path

    def revert_execute(self, path: str, result: str, failure: Any):
        """ Remove the created file.
        """
        if os.path.exists(result):
            os.remove(result)

execute(path)

Creates an empty file at the specified path.

Source code in client/ayon_workflow/plugin_system/example.py
83
84
85
86
87
88
def execute(self, path: str) -> str:
    """ Creates an empty file at the specified path.
    """
    with open(path, "w") as f:
        f.write("")
    return path

revert_execute(path, result, failure)

Remove the created file.

Source code in client/ayon_workflow/plugin_system/example.py
90
91
92
93
94
def revert_execute(self, path: str, result: str, failure: Any):
    """ Remove the created file.
    """
    if os.path.exists(result):
        os.remove(result)

MultiIntegerAddition

Bases: WorkflowNode

Add two integers together.

Source code in client/ayon_workflow/plugin_system/example.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class MultiIntegerAddition(WorkflowNode):
    """ Add two integers together.
    """
    version: str = "0.0.1"
    inputs = {
        "multi": {
            "description": "A bunch of integers to add.",
            "allow_multi_connection": True,
        },
    }
    outputs = {
        "result": {
            "description": "The result of the addition.",
        },
    }

    def execute(self, multi_input: Union[int, list[int]]) -> int:
        """ Add a bunch of integers together.
        """
        if isinstance(multi_input, list):
            return sum(multi_input)

        return multi_input

execute(multi_input)

Add a bunch of integers together.

Source code in client/ayon_workflow/plugin_system/example.py
53
54
55
56
57
58
59
def execute(self, multi_input: Union[int, list[int]]) -> int:
    """ Add a bunch of integers together.
    """
    if isinstance(multi_input, list):
        return sum(multi_input)

    return multi_input

MultiOutputNode

Bases: WorkflowNode

An example node that returns multiple outputs.

Source code in client/ayon_workflow/plugin_system/example.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class MultiOutputNode(WorkflowNode):
    """ An example node that returns multiple outputs.
    """

    version: str = "0.0.1"
    inputs = {}
    outputs = {
        "output_1": {
            "description": "The first output.",
        },
        "output_2": {
            "description": "The second output.",
        },
    }

    def execute(self) -> tuple[int, str]:
        """ Return two outputs of different types.
        """
        return 42, "hello"

execute()

Return two outputs of different types.

Source code in client/ayon_workflow/plugin_system/example.py
111
112
113
114
def execute(self) -> tuple[int, str]:
    """ Return two outputs of different types.
    """
    return 42, "hello"