Skip to content

Commit 2c6c290

Browse files
authored
Merge pull request #61 from ynput/enhancement/support_free_version
Make ayon-resolve support free DaVinci Resolve version.
2 parents fc871cb + 8afc7e9 commit 2c6c290

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

client/ayon_resolve/api/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
resolve api
33
"""
44
from .utils import (
5-
get_resolve_module
5+
get_resolve_module,
6+
set_resolve_module
67
)
78

89
from .pipeline import (
@@ -96,6 +97,7 @@
9697

9798
# utils
9899
"get_resolve_module",
100+
"set_resolve_module",
99101

100102
# lib
101103
"maintain_current_timeline",

client/ayon_resolve/api/menu.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ def on_set_resolution_clicked(self):
145145

146146

147147
def launch_ayon_menu():
148-
app = QtWidgets.QApplication(sys.argv)
148+
app = (
149+
QtWidgets.QApplication.instance()
150+
or QtWidgets.QApplication(sys.argv)
151+
)
149152

150153
ayon_menu = AYONMenu()
151154

client/ayon_resolve/api/pipeline.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232

3333
from . import constants
3434
from . import lib
35-
from .utils import get_resolve_module
35+
from .utils import (
36+
get_resolve_module,
37+
set_resolve_module
38+
)
3639
from .workio import (
3740
open_file,
3841
save_file,
@@ -56,6 +59,7 @@
5659

5760
class ResolveHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
5861
name = "resolve"
62+
_app = None
5963

6064
def install(self):
6165
"""Install resolve-specific functionality of avalon-core.
@@ -79,11 +83,31 @@ def install(self):
7983
register_creator_plugin_path(CREATE_PATH)
8084
register_inventory_action_path(INVENTORY_PATH)
8185

86+
# DaVinci Resolve version >= 20
87+
# Set api resolve modules from undocumented injected cached app.
88+
# https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=113252
89+
try:
90+
bmdvf = self._app
91+
bmdvr = self._app.GetResolve()
92+
93+
if not bmdvr:
94+
raise RuntimeError("Expecting valid Resolve module from app.")
95+
96+
set_resolve_module(bmdvr, bmdvf)
97+
98+
# If any issue, default to DaVinci Resolve Studio mechanism.
99+
except Exception as error:
100+
log.info(
101+
"Could not gather resolve apps from cached entry point %r. "
102+
"Default to DaVinci Resolve Studio specific logic.",
103+
error,
104+
)
105+
get_resolve_module()
106+
82107
# register callback for switching publishable
83108
pyblish.register_callback("instanceToggled",
84109
on_pyblish_instance_toggled)
85110

86-
get_resolve_module()
87111

88112
def open_workfile(self, filepath):
89113
success = open_file(filepath)
@@ -119,6 +143,12 @@ def update_context_data(self, data, changes):
119143
# TODO: implement to support persisting context attributes
120144
pass
121145

146+
@classmethod
147+
def set_resolve_modules_from_app(cls, app):
148+
""" Cache injected entry point "app" as class variable for re-use.
149+
"""
150+
cls._app = app
151+
122152
@staticmethod
123153
def _show_ayon_settings_confirmation_windows():
124154
"""

client/ayon_resolve/api/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,17 @@ def get_resolve_module():
7575
# assign global var and return
7676
bmdvr = bmd.scriptapp("Resolve")
7777
bmdvf = bmd.scriptapp("Fusion")
78-
api.bmdvr = bmdvr
79-
api.bmdvf = bmdvf
78+
set_resolve_module(bmdvr, bmdvf)
79+
80+
81+
def set_resolve_module(resolve_app, fusion_app):
82+
""" Set Fusion and Resolve app as public api modules.
83+
"""
84+
from ayon_resolve import api
85+
86+
api.bmdvr = resolve_app
87+
api.bmdvf = fusion_app
88+
8089
log.info(("Assigning resolve module to "
8190
f"`ayon_resolve.api.bmdvr`: {api.bmdvr}"))
8291
log.info(("Assigning resolve module to "

client/ayon_resolve/plugins/load/load_media.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ def _get_container_data(self, context: dict) -> dict:
382382
data[key] = version["attrib"][key]
383383

384384
# version.data
385-
for key in ["author"]:
386-
data[key] = version["data"][key]
385+
if "author" in version["data"]:
386+
data["author"] = version["data"]["author"]
387387

388388
# add variables related to version context
389389
data.update({

client/ayon_resolve/startup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
log = Logger.get_logger(__name__)
1717

1818

19+
# Undocumented app variable is injected by Resolve automatically
20+
# https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=113252
21+
app: object # noqa: F821
22+
23+
1924
def ensure_installed_host():
2025
"""Install resolve host with openpype and return the registered host.
2126
@@ -27,6 +32,11 @@ def ensure_installed_host():
2732
if host:
2833
return host
2934

35+
# Register injected "app" variable at class level for future uses.
36+
# For free version of DaVinci Resolve, this seems to be
37+
# the only way to gather the Resolve/Fusion applications.
38+
ayon_resolve.api.ResolveHost.set_resolve_modules_from_app(app) # noqa: F821
39+
3040
host = ayon_resolve.api.ResolveHost()
3141
install_host(host)
3242
return registered_host()

client/ayon_resolve/utility_scripts/AYON__Menu.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
log = Logger.get_logger(__name__)
88

99

10+
# Undocumented app variable is injected by Resolve automatically
11+
# https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=113252
12+
app: object # noqa: F821
13+
14+
1015
def main(env):
1116
from ayon_resolve.api import ResolveHost, launch_ayon_menu
1217

18+
# Register injected "app" variable at class level for future uses.
19+
# For free version of DaVinci Resolve, this seems to be
20+
# the only way to gather the Resolve/Fusion applications.
21+
ResolveHost.set_resolve_modules_from_app(app) # noqa: F821
22+
1323
# activate resolve from openpype
1424
host = ResolveHost()
1525
install_host(host)

0 commit comments

Comments
 (0)