[Davinci17]GUIの作成 With Fusion’s UI Manager

CG

DavinciでGUIの機能が欲しかったのですが、マシン環境にPySideをインストールするわけにはいかず、
標準モジュールのFusionを使用してGUIを作成しました。

Davinciのバージョンは17です。

スクリプト実行方法

Workspace > Console を選択。
pythonなのでPy2のモードにかえて入力。

Source Code

ui = fu.UIManager
disp = bmd.UIDispatcher(ui)
dlg = disp.AddWindow({ "WindowTitle": "My First Window", "ID": "MyWin", "Geometry": [ 100, 100, 400, 100 ], },
    [
        ui.VGroup({ "Spacing": 5, },
        [
            # Add your GUI elements here:
            ui.Label({ "ID": "MyLabel", "Text": "Hello World", }),
            ui.Button({ "ID": "MyButton", "Text": "Push me!!!",}),
        ]),
    ])
itm = dlg.GetItems()
def _clicked(ev):
    print(itm['MyLabel'].Text)
dlg.On.MyButton.Clicked = _clicked
 
# The window was closed
def _func(ev):
    disp.ExitLoop()
dlg.On.MyWin.Close = _func
dlg.Show()
disp.RunLoop()
dlg.Hide()

ボタンを押してテキストの値を取得してプリント

Available GUI Elements

下記のGUIを組込むことができるようです。

  • ui:VGroup{}
  • ui:HGroup{}
  • ui:Stack{}
  • ui:VGap{}
  • ui:HGap{}
  • ui:Button{}
  • ui:CheckBox{}
  • ui:ColorPicker{}
  • ui:ComboBox{}
  • ui:DoubleSpinBox{}
  • ui:Label{}
  • ui:LineEdit{}
  • ui:Slider{}
  • ui:SpinBox{}
  • ui:TabBar{}
  • ui:TextEdit{}
  • ui:Tree{}

環境構築

Davinciで用意されているModuleを使用するためには環境変数を設定する必要があります。

参考リンク:https://diop.github.io/davinci-resolve-api/#/

  • Mac OS X:
    RESOLVE_SCRIPT_API="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/"
    RESOLVE_SCRIPT_LIB="/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so"
    PYTHONPATH="$PYTHONPATH:$RESOLVE_SCRIPT_API/Modules/"
  • Windows:
    RESOLVE_SCRIPT_API="%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\"
    RESOLVE_SCRIPT_LIB="C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll"
    PYTHONPATH="%PYTHONPATH%;%RESOLVE_SCRIPT_API%\Modules\"
  • Linux:
    RESOLVE_SCRIPT_API="/opt/resolve/Developer/Scripting/"
    RESOLVE_SCRIPT_LIB="/opt/resolve/libs/Fusion/fusionscript.so"
    PYTHONPATH="$PYTHONPATH:$RESOLVE_SCRIPT_API/Modules/"
    (Note: For standard ISO Linux installations, the path above may need to be modified to refer to /home/resolve instead of /opt/resolve)

またはsysのModuleを使用して追加

import sys
sys.path.append(r'/path/to/resolve/Developer/Scripting/Modules/')

参考 -フィルパスを変更-

import DaVinciResolveScript as dvr_script
resolve = dvr_script.scriptapp("Resolve")
project_manager = resolve.GetProjectManager()
currentProject = project_manager.GetCurrentProject()
mediapool = currentProject.GetMediaPool()
folder = mediapool.GetCurrentFolder()
clips = folder.GetClipList()
for clip in clips:
    filename = clip.GetClipProperty("File Path")
    newpath = r'/path/to/file'
    clip.ReplaceClip(newpath)

newpathを任意で変更してください。

参考リンク

https://diop.github.io/davinci-resolve-api/#/