Scripting API; Can't set still label with GUI

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

ambustion

  • Posts: 25
  • Joined: Mon Jun 24, 2019 4:36 pm
  • Real Name: Brendon Rathbone

Scripting API; Can't set still label with GUI

PostSat Jan 22, 2022 4:59 am

I have a small script to set a still label. The simple version of the script that works is here:
Code: Select all
label="test"
projectManager=resolve.GetProjectManager()
project=projectManager.GetCurrentProject()
gallery=project.GetGallery()
current_album=gallery.GetCurrentStillAlbum()
still=timeline.GrabStill()
current_album.SetLabel(still , label)


If I run this in a resolve gui I am unable to succesfully set the label but running that code by itself will set the label(preventing me from getting user input).

This is code that will not work. I am also running this on Resolve 17.4.2 on Windows 10.

Does anyone have any ideas on why it wouldn't work when spawning a gui window?

import sys
import os

###env initialization
from sys import platform
if platform == "linux" or platform == "linux2":
env = "linux"
Resolve_Loc = r'/opt/resolve/Developer/Scripting/Modules'
print("Linux OS")
elif platform == "darwin":
env = "mac"
Resolve_Loc=r'/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules'
print("System is mac OS")
elif platform == "win32":
env = "win"
Resolve_Loc=r'C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\Modules'
print("Windows OS")
else:
print("error getting system platform")
sys.path.insert(1,Resolve_Loc)

import DaVinciResolveScript as bmd

ScriptDir = os.path.dirname(os.path.realpath(sys.argv[0]))
fu = bmd.scriptapp('Fusion')
resolve = bmd.scriptapp('Resolve')
ui = fu.UIManager
disp = bmd.UIDispatcher(ui)


dlg = disp.AddWindow({"WindowTitle": "StillLabel", "ID": "MyWin", "Geometry": [100, 100, 1000, 250], },
[
ui.VGroup({"Spacing": 2, },
[
# Add your GUI elements here:
ui.Label({"ID": "Timeline", "Text": "Enter Still Label", "Weight": 0.5}),
ui.LineEdit({"ID":"label"}),
ui.Button({"ID":"AddButton", "Text":"Add"}),
ui.Button({"ID":"Close", "Text":"Close"}),
]),
])
itm = dlg.GetItems()
def _func(ev):
disp.ExitLoop()
dlg.On.MyWin.Close = _func

def _func(ev):
disp.ExitLoop()
dlg.On.Close.Clicked = _func

def _func(ev):
#label="My Custom Label"
label=str(itm["label"].Text)
projectManager=resolve.GetProjectManager()
project=projectManager.GetCurrentProject()
gallery=project.GetGallery()
current_album=gallery.GetCurrentStillAlbum()
still=timeline.GrabStill()
current_album.SetLabel(still , label)
dlg.On.AddButton.Clicked = _func

dlg.Show()
disp.RunLoop()
dlg.Hide()
Offline
User avatar

roger.magnusson

  • Posts: 3398
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Scripting API; Can't set still label with GUI

PostSat Jan 22, 2022 12:31 pm

You're using a variable called timeline but you haven't populated it.

Add this before you execute GrabStill():
timeline = project.GetCurrentTimeline()
Offline

ambustion

  • Posts: 25
  • Joined: Mon Jun 24, 2019 4:36 pm
  • Real Name: Brendon Rathbone

Re: Scripting API; Can't set still label with GUI

PostSat Jan 22, 2022 6:58 pm

roger.magnusson wrote:You're using a variable called timeline but you haven't populated it.

Add this before you execute GrabStill():
timeline = project.GetCurrentTimeline()


Doh, well that was obvious. Thank you so much! Your Class Browser script has gotten a lot of use while learning this API.

Return to DaVinci Resolve

Who is online

Users browsing this forum: Alexrocks1253, Bing [Bot], franciscovaldez, Gary Hango, Julyan23, Mads Johansen, Noerde, ohimbz, PeterBrown, Yahoo [Bot] and 198 guests