Python API Question "Job Id" [Solved]

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

zzohan619

  • Posts: 14
  • Joined: Fri May 29, 2020 6:11 pm
  • Location: Odessa, Ukraine
  • Real Name: Nikita Abramov

Python API Question "Job Id" [Solved]

PostFri Oct 15, 2021 10:09 am

Hi guys. How to use new Job Id? What is it? And why this code doesn't work?
Windows 10 Resolve 17.3.2 Python 3.6
Code: Select all
projectManager = resolve.GetProjectManager()
project = projectManager.GetCurrentProject()
project.DeleteRenderJob("Job 1")


DeleteRenderJob(jobId) --> Bool # Deletes render job for input job id (string).
Last edited by zzohan619 on Fri Oct 15, 2021 5:17 pm, edited 1 time in total.
Offline

zzohan619

  • Posts: 14
  • Joined: Fri May 29, 2020 6:11 pm
  • Location: Odessa, Ukraine
  • Real Name: Nikita Abramov

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 10:24 am

Okay. I found answer couple minute later. By looking at example code by BMD.

By using GetRenderJobList you can see jobId. For my Job 1 it's '98735a44-5810-4d7c-af65-08a3e6ff936e'
Offline

zzohan619

  • Posts: 14
  • Joined: Fri May 29, 2020 6:11 pm
  • Location: Odessa, Ukraine
  • Real Name: Nikita Abramov

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 10:33 am

Anybody has a tip on getting jobid of last rendered job?
Offline
User avatar

roger.magnusson

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

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 12:34 pm

You can't get the last rendered job as in find out when in time a job was rendered. But project.GetRenderJobList() has the jobs in the order they were added and you can use project.GetRenderJobStatus(jobId) to find out if it has ever been rendered or is currently being rendered.

You can of course go through all jobs in project.GetRenderJobList() and use TargetDir and OutputFilename to get the properties of the rendered files.

If all you want to do is do something with a file after it was rendered you should trigger a script from the Render Settings > Advanced Settings > Trigger script option instead. See how in the sample provided by BMD: 8_slack_notification_by_render_job.py
Offline

zzohan619

  • Posts: 14
  • Joined: Fri May 29, 2020 6:11 pm
  • Location: Odessa, Ukraine
  • Real Name: Nikita Abramov

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 1:31 pm

roger.magnusson wrote:You can't get the last rendered job as in find out when in time a job was rendered. But project.GetRenderJobList() has the jobs in the order they were added and you can use project.GetRenderJobStatus(jobId) to find out if it has ever been rendered or is currently being rendered.

You can of course go through all jobs in project.GetRenderJobList() and use TargetDir and OutputFilename to get the properties of the rendered files.

If all you want to do is do something with a file after it was rendered you should trigger a script from the Render Settings > Advanced Settings > Trigger script option instead. See how in the sample provided by BMD: 8_slack_notification_by_render_job.py


Thanks I actually desire something similar but message to telegram. But I'd like to send message only if render job is successful. And I'd prefer everything in one script.

I'm just not that experienced with Python to deal with such complex dictionaries. I would appreciate the help.

My code so far:

Code: Select all
project = resolve.GetProjectManager().GetCurrentProject()
projname = project.GetName()

RenderType = ['RUS', 'ENG', 'Sound']


timeline = project.GetCurrentTimeline()
timelinename =  timeline.GetName()
if timelinename == f"{projname}_ENG":
    RenderType = ['ENG', 'Sound']
else:
    timeline = project.GetTimelineByIndex(1)

project.SetCurrentTimeline(timeline)
resolve.OpenPage("Deliver")
project.DeleteAllRenderJobs()


if timeline.GetTrackName("audio", 2) != "ENG":
    RenderType = ["RUS"]


for type in RenderType:
    TargetDir = f"E:/Dropbox (TroomHand)/Папка рабочей группы TroomHand/Nikita_montag/{projname}/{type}"
    project.LoadRenderPreset(type)
    if type == "ENG":
        index = 1
        timelinecount = project.GetTimelineCount()
        while index <= timelinecount:
            timeline = project.GetTimelineByIndex(index)
            timelinename = timeline.GetName()
            index += 1
            print(timelinename)
            if timelinename == f"{projname}_ENG":
                print(f"start {timelinename}")
                project.SetCurrentTimeline(timeline)
            else:
                timeline = projname
    if type == "Sound":
        TargetDir = f"E:/Dropbox (TroomHand)/Папка рабочей группы TroomHand/Nikita_montag/{projname}/{type}"
    renderset = project.SetRenderSettings({"SelectAllFrames": 1,
                                           "TargetDir": TargetDir,
                                           'CustomName': f"{projname}_{type}"})
    project.AddRenderJob()

project.StartRendering()

import time
while True:
  if not project.IsRenderingInProgress():
      # Confusing Part
      TypeLen = len(RenderType)
      jobList = project.GetRenderJobList()

      # Here we get JobId equal to TypeLen

      JobStatus = project.GetRenderJobStatus(TypeLen)
      print(JobStatus)
      if JobStatus == "Cancelled":
          sys.exit(0)

      print("telegram started")
      import requests
      API_link = f'https://api.telegram.org/bot{API}'
      sent_message = requests.get(API_link + f'/sendMessage?chat_id={chat_id}&text=Привет, {supervisor}. {projname}_{RenderType}, Готов. Приятного Просмотра. @zzohan619')
      break
  time.sleep(3)
print("done!")

Offline
User avatar

roger.magnusson

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

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 2:10 pm

project.AddRenderJob() returns the jobId, so you don't have use project.GetRenderJobList() to find the job details.
Offline

zzohan619

  • Posts: 14
  • Joined: Fri May 29, 2020 6:11 pm
  • Location: Odessa, Ukraine
  • Real Name: Nikita Abramov

Re: Python API Question "Job Id"

PostFri Oct 15, 2021 5:16 pm

roger.magnusson wrote:project.AddRenderJob() returns the jobId, so you don't have use project.GetRenderJobList() to find the job details.


Thank you very much!
Here's working code

Code: Select all

jobid = []
# Your code here
    jobid.append(project.AddRenderJob())
project.StartRendering()

import time

while True:
    if not project.IsRenderingInProgress():
        import sys

        JobStatus = project.GetRenderJobStatus(jobid[(len(RenderType) - 1)])
        if list(JobStatus.values())[0] == "Cancelled":
            print("Render failed")
            sys.exit(0)
        # Your code here
        break
time.sleep(3)
print("done!")


Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], FranzDev78, Michael Tebinka, piankamontazowa and 170 guests