Pyblish plugin for incrementing workfile version after successful publish.
This module contains a plugin that automatically increments the current workfile version number after a successful publish operation in MD.
IncrementWorkfileVersion
Bases: ContextPlugin
Increment current workfile version.
Source code in client/ayon_marvelousdesigner/plugins/publish/increment_workfile.py
14
15
16
17
18
19
20
21
22
23
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
55
56
57
58
59
60
61
62
63
64 | class IncrementWorkfileVersion(pyblish.api.ContextPlugin):
"""Increment current workfile version."""
order = pyblish.api.IntegratorOrder + 1
label = "Increment Workfile Version"
optional = True
hosts: ClassVar[list[str]] = ["marvelousdesigner"]
def process(self, context: pyblish.api.Context) -> None:
"""Process the context to increment the workfile version.
Args:
context (pyblish.api.Context): The publishing context.
Raises:
KnownPublishError: If the publishing was not successful.
"""
if not all(result["success"] for result in context.data["results"]):
msg = "Publishing not successful so version is not increased."
raise KnownPublishError(msg)
host = registered_host()
current_filepath = context.data["currentFile"]
try:
from ayon_core.host.interfaces import SaveWorkfileOptionalData
from ayon_core.pipeline.workfile import save_next_version
current_filename = os.path.basename(current_filepath)
save_next_version(
description=(
f"Incremented by publishing from {current_filename}"
),
# Optimize the save by reducing needed queries for context
prepared_data=SaveWorkfileOptionalData(
project_entity=context.data["projectEntity"],
project_settings=context.data["project_settings"],
anatomy=context.data["anatomy"],
)
)
new_filepath = host.get_current_workfile()
except ImportError:
# Backwards compatibility before ayon-core 1.5.0
self.log.debug(
"Using legacy `version_up`. Update AYON core addon to "
"use newer `save_next_version` function."
)
new_filepath = version_up(current_filepath)
host.save_workfile(new_filepath)
self.log.info("Incrementing current workfile to: %s", new_filepath)
|
process(context)
Process the context to increment the workfile version.
Parameters:
| Name | Type | Description | Default |
context | Context | | required |
Raises:
| Type | Description |
KnownPublishError | If the publishing was not successful. |
Source code in client/ayon_marvelousdesigner/plugins/publish/increment_workfile.py
22
23
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
55
56
57
58
59
60
61
62
63
64 | def process(self, context: pyblish.api.Context) -> None:
"""Process the context to increment the workfile version.
Args:
context (pyblish.api.Context): The publishing context.
Raises:
KnownPublishError: If the publishing was not successful.
"""
if not all(result["success"] for result in context.data["results"]):
msg = "Publishing not successful so version is not increased."
raise KnownPublishError(msg)
host = registered_host()
current_filepath = context.data["currentFile"]
try:
from ayon_core.host.interfaces import SaveWorkfileOptionalData
from ayon_core.pipeline.workfile import save_next_version
current_filename = os.path.basename(current_filepath)
save_next_version(
description=(
f"Incremented by publishing from {current_filename}"
),
# Optimize the save by reducing needed queries for context
prepared_data=SaveWorkfileOptionalData(
project_entity=context.data["projectEntity"],
project_settings=context.data["project_settings"],
anatomy=context.data["anatomy"],
)
)
new_filepath = host.get_current_workfile()
except ImportError:
# Backwards compatibility before ayon-core 1.5.0
self.log.debug(
"Using legacy `version_up`. Update AYON core addon to "
"use newer `save_next_version` function."
)
new_filepath = version_up(current_filepath)
host.save_workfile(new_filepath)
self.log.info("Incrementing current workfile to: %s", new_filepath)
|