Creating Scripts for DaVinci Resolve

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

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 3:57 pm

Moving timeline markers to timeline items and/or media pool items is perhaps more involved than one might think at first.

These considerations come to mind:
  • The placement of each clip on the timeline
  • Which track a clip marker should be added to if there are clips on multiple tracks
  • Whether or not the clip is trimmed and the marker needs to be offset
  • Overwrite existing markers or not?
  • Should duration markers only be added if the clip on the timeline covers the whole duration of the marker?
I have a prototype for it but I'd like to polish it up a bit before posting it.
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 4:46 pm

roger.magnusson wrote:Moving timeline markers to timeline items and/or media pool items is perhaps more involved than one might think at first.

These considerations come to mind:
  • The placement of each clip on the timeline
  • Which track a clip marker should be added to if there are clips on multiple tracks
  • Whether or not the clip is trimmed and the marker needs to be offset
  • Overwrite existing markers or not?
  • Should duration markers only be added if the clip on the timeline covers the whole duration of the marker?
I have a prototype for it but I'd like to polish it up a bit before posting it.


Great!!!
In fact to copy timeline markers to media-clip markers is not a 1:1 operation. By default I'd guess (thinking of my own workflow) one would want to:

  • Copy timeline-markers only onto the media-clips represented by timeline-clips on one video track. That video track could be chosen or simple be the lowest. Otherwise things get much too complicated.
  • If there are more than one instances of a media-clip on the timeline, copy successively all timeline markers to the respective media-clip.
  • Only delete those media-clip markers that are within the range of the media-clip's instance(s) on the timeline. One would have to first successively delete all media-clip markers within the range of all instances on the timeline, and only then copy all timeline markers onto the respective media-clip.
  • Timeline-duration-markers that span more than one timeline-clip should be copied only onto the media-clip represented by the clip where the duration marker starts, but maintaining (on the media-clip) the total duration of the timeline-marker (unless it exceed the media-clip's length).
Last edited by pantau000 on Wed Feb 15, 2023 5:22 pm, edited 5 times in total.
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 4:50 pm

I was orginally thinking of starting with timeline markers, but yes, if you already have clip markers it's more straightforward.
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 4:54 pm

roger.magnusson wrote:I was orginally thinking of starting with timeline markers, but yes, if you already have clip markers it's more straightforward.

Actually I put it wrong, I was talking about timeline-markers too. I'll edit the post. The more one thinks about it, the more complicated it gets. The problem is that Resolve makes a difference between media-clip markers timeline-clip markers. However, as only media-clip markers get preserved in the sense that they will move with the clip if applied to another timeline, I'd say it would be much more useful to be able to copy timeline markers to media-clips.
Offline
User avatar

waltervolpatto

  • Posts: 10540
  • Joined: Thu Feb 07, 2013 5:07 pm
  • Location: 1146 North Las Palmas Ave. Hollywood, California 90038 USA

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 5:42 pm

can this be a sticky?
W10-19043.1645- Supermicro MB C9X299-PGF - RAM 128GB CPU i9-10980XE 16c 4.3GHz (Oc) Water cooled
Decklink Studio 4K (12.3)
Resolve 18.5.1 / fusion studio 18
GPU 3090ti drivers 512.59 studio
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 1:44 am

The full marker transfer script will have to be put on hold for now. That's a script where timeline markers can be copied/moved to timeline clip markers and media pool clips. Resolve has a bug where a script can't create clip markers in a timeline if the marker ends at the end of the clip. Doing it manually works but it fails when doing the same using a script (TimelineItem.AddMarker()).

A smaller script for updating media pool clip markers from timeline clip markers should still be possible though, unless I find something else along the way.
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 11:48 am

roger.magnusson wrote:A smaller script for updating media pool clip markers from timeline clip markers should still be possible though, unless I find something else along the way.

That would already be extremely useful.
Offline
User avatar

roger.magnusson

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

Copy Timeline Clip Markers to Media Pool

PostThu Feb 16, 2023 1:04 pm

Ok, here's the smaller marker transfer script. All it does is copy timeline clip markers to matching media pool clips.

If there are markers on the same frame for both audio and video, the marker on the video clip is used.
If there are multiple instances on the timeline of the same clip with markers on the same frame, the first encountered marker is used.

Image
Image

Known Issues
As mentioned before, the DaVinci Resolve scripting API marker functions do not include keywords, meaning this script will strip any assigned keywords from markers it processes.

Download
Copy Timeline Clip Markers to Media Pool.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:11 pm, edited 4 times in total.
Offline

AssistantEditor1

  • Posts: 108
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 1:10 pm

roger.magnusson wrote:Ok, here's the smaller marker transfer script. All it does is copy timeline clip markers to matching media pool clips.

If there are markers on the same frame for both audio and video, the marker on the video clip is used.


Download
Copy Timeline Clip Markers to Media Pool.lua


You’re a wizard.

Great stuff
Offline
User avatar

Igor Riđanović

  • Posts: 1605
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 5:47 pm

pantau000 wrote:
roger.magnusson wrote:For a Lua script you need to use the colon symbol when invoking the Resolve API methods. Like this:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem(marker_frame)
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

But note that GetMediaPoolItem() doesn't take any parameters.

Thanks, but this is all still a mystery to me...
Would I have to include this line to get the item?
Code: Select all
timelineitem = timeline.GetCurrentVideoItem()

And then:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem()
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)


Yes, you first have to get a timeline item, then you have to find the clip in the bin this timeline item has come from. Note there is a typo in the code. There are timelneItem and timelineItem. Either is fine but they can't differ. This is just the name we use to label the object that represents the actual timeline item. The name can be anything.
www.metafide.com - DaVinci Resolve™ Apps
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 8:47 pm

I'm experiencing an unusual behavior in Resolve 18.1.2 / 18.1.1 when attempting to add markers to a timeline using the timline.AddMarker() function. Specifically, when my timeline starts at 01:00:00:00, the frame count seems to add an extra hour, resulting in misplaced markers.

For example, on a 24FPS timeline, the following code:
Code: Select all
tl.AddMarker(86400, 'Blue', 'Hello', 'World', 1)

Places the marker at 172800 record frame instead of the intended location.

Similarly, on a 25FPS timeline, this code:
Code: Select all
tl.AddMarker(90000, 'Blue', 'Hello', 'World', 1)

Adds the marker at 180000 frame instead of the intended location.

However, when I set the timeline starting TC to 00:00:00:00 and use the following code:
Code: Select all
tl.AddMarker(0, 'Blue', 'Hello', 'World', 1)

the marker is added at frame 0 as expected.

I've used AddMarker() many times before, and this is the first time I've encountered this issue. I've tested this on both Windows and Mac machines with versions 18.1.1 and 18.1.2 of Resolve. Has anyone else experienced this problem before?
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 9:26 pm

Yeah, not sure why they did that but you need to offset with timeline.GetStartFrame(). I might be confusing it with something else but I thought it was always like this.
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 16, 2023 9:35 pm

I see.
Ok, thanks for the tip.
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Creating Scripts for DaVinci Resolve

PostFri Feb 17, 2023 8:41 am

Find_In_Timline

Here is a python script to find a clip from the media pool in the active timeline.

The script searches for a flagged clip in the Media Pool active bin and adds a marker to the active timeline for each occurrence of the clip.

[*]The clip must have a 'Cream' flag set in order to be recognized by the script.

[*]The script expects only one clip to be flaged as 'Cream' . If more than one clip is flagged the script will only look for the first item it founds.

I couldn't find a way to get the selected clip in the bin so I had to use flag to identify the target clip.

you can copy the code here:
Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
This script searches for a flagged clip in the Media Pool active bin and adds a marker to the active timeline for each occurrence of the clip.

The clip must have a 'Cream' flag set in order to be recognized by the script.

The script searches for the flagged source clip in the current bin in the Media Pool. If no flagged clip is found, the script exits. Otherwise, the script iterates over all video items
in the timeline and checks if their name matches the name of the flagged source clip. If a match is found, the script adds a marker to the timeline at the start of the matched item.

Note:
The script expects only one clip to be flaged as 'Cream' . If more than one clip is flagged the script will only look for the first item it founds.

Iddolahman@gmail.com
https://www.opus-tv.com/
"""

import sys
import DaVinciResolveScript as bmd


def get_flaged_clip(folder):
    """Returns the first clip in the given media folder that has the 'Cream' flag set.
    Args:
        folder (MediaPoolFolder): The media pool folder to search for the flagged clip.
    Returns:
        Media Pool Item: The first flagged clip found in the folder, or None if no clip is found.
    """
    for clip in folder.GetClipList():
        if clip.GetClipProperty()['Flags'] == 'Cream':
            return clip
    return None


def main():
    """Main function that searches for a flagged clip in the media pool and adds a marker to its occurrences in the timeline."""
    # Get the current Resolve project and media pool.
    resolve = bmd.scriptapp('Resolve')
    projectManager = resolve.GetProjectManager()
    proj = projectManager.GetCurrentProject()
    mediaPool = proj.GetMediaPool()

    # Get the current media pool folder, timeline, and video track count.
    folder = mediaPool.GetCurrentFolder()
    tl = proj.GetCurrentTimeline()
    offset = tl.GetStartFrame()
    videoTrackCount = tl.GetTrackCount('video')

    # Find the flagged source clip in the media pool.
    sourceClip = get_flaged_clip(folder)

    # If no flagged clip is found, exit the program.
    if sourceClip == None:
        print('No clips flagged')
        sys.exit()

    # Find all video items in the timeline and check if they match the flagged source clip.
    timelineItems = []
    for trackNumber in range(videoTrackCount):
        timelineItems.extend(tl.GetItemListInTrack('video', trackNumber+1))

    for item in timelineItems:
        if item.GetName() == sourceClip.GetName():
            # If an item matches the flagged source clip, add a marker to the timeline.
            recordFrame = item.GetStart()
            tl.AddMarker(recordFrame - offset, 'Cream', 'Found One', '', 1, '')

    # Save the project to disk.
    projectManager.SaveProject()


if __name__ == "__main__":
    main()


Or from the GitHub repository:
https://github.com/Iddos-l/Find_In_Timeline

Edit:
Made some modifications to the GitHub repo.
Last edited by iddos-l on Wed May 17, 2023 6:03 am, edited 1 time in total.
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Copy Timeline Clip Markers to Timeline

PostThu Feb 23, 2023 6:40 pm

I forked two of Roger's scripts to copy timeline clip markers to the timeline itself.

Below is the corrected version that only copies visible markers (and at the right place).
Attachments
Copy Timeline Clip Markers to Timeline.7z
(2.85 KiB) Downloaded 962 times
Last edited by pantau000 on Tue Feb 28, 2023 7:57 pm, edited 4 times in total.
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 26, 2023 8:21 pm

Nice! I think one thing is missing, if a clip has been trimmed on the timeline you need to account for the left offset.
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 26, 2023 8:59 pm

roger.magnusson wrote:Nice! I think one thing is missing, if a clip has been trimmed on the timeline you need to account for the left offset.

Good point... You mean GetMarkers(TimelineItem) also gets the not visible markers?

Well, just checked, it does, I will have to take care of that... Thanks for pointing it out.
Offline

AssistantEditor1

  • Posts: 108
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 26, 2023 10:43 pm

pantau000 wrote:I forked two of Roger's scripts to copy timeline clip markers to the timeline itself.


Thanks!
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostMon Feb 27, 2023 2:34 pm

roger.magnusson wrote:Nice! I think one thing is missing, if a clip has been trimmed on the timeline you need to account for the left offset.

Should be working correctly now.
Offline
User avatar

roger.magnusson

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

Set Timecode for Media Pool Clips

PostTue Feb 28, 2023 7:41 pm

If you're just here for the download, it's at the bottom of the post as usual.

What do we have here? On the surface it's an incredibly simple script that can set the timecode for media pool clips. It can set a specific timecode or an offset using timecode or frames. It works on the selected bin and optionally on any sub folders in the bin.

ImageImage

The original timecode can optionally be stored in a metadata field before changing it, allowing us to also restore the original timecode later.

But the party trick of this script is that it finally comes with my take on how to tackle the issue of scripts crashing if the automated project backup starts while running. It involves wrapping the DaVinci Resolve function in the script:retry() function. Not all API functions are affected by this issue, but generally the ones that change object properties are.

As far as I can tell, automated backups don't start if a script is running from the console, so that's good but it doesn't help when running scripts from the Scripts menu (as of DaVinci Resolve 18). It does however seem like it would be easy for BMD to provide a mechanism for suspending backups via the API. It would certainly save a lot of work in trying to make scripts more robust.

The script has four new useful reusable components:
  • Retry - A way to make DaVinci Resolve scripts resilient to issues that otherwise stop execution:
    • When the automated project backup starts
    • When the user opens a modal window
  • Progress bar - A GUI progress bar that updates using events
    Image
  • Bin traversal - Gets the entire media pool tree and provides a function for traversing it in branch order

  • Log - Write log entries using simple Lua tables that are then shown in a Tree control when the script has completed
Image
Console snippet

Here's a bare-bones snippet you can execute directly in the console for setting the timecode of all clips in the current bin. It ignores timelines and compound clips etc. By the way, "current bin" means the one selected in the Bin List, where only bins are listed. And you can only select one. That's a limitation of the current scripting API.

Code: Select all
local timecode = "00:00:00:00"
local project = assert(resolve:GetProjectManager():GetCurrentProject(), "Couldn't get current project")
local media_pool = project:GetMediaPool()
local selected_folder = media_pool:GetCurrentFolder()
local initial_page = resolve:GetCurrentPage()
resolve:OpenPage("deliver")

for i, media_pool_item in ipairs(iif(selected_folder, selected_folder, media_pool:GetRootFolder()):GetClipList()) do
    if #media_pool_item:GetClipProperty("Format") > 0 then
        assert(media_pool_item:SetClipProperty("Start TC", timecode), string.format("Couldn't set clip property on clip %s", i))
        print(string.format("%s - OK", i))
    else
        print(string.format("%s - Ignored", i))
    end
end

resolve:OpenPage(initial_page)

You might be tempted to look at GetClipProperty("Type") to determine the type of a clip. But this, like a few other properties in Resolve, is translated to the language Resolve is currently set to. So if you're making scripts for other people I would avoid this property unless it's just used for listing.

While running the script we switch to the Deliver page for two reasons:
  1. Performance while updating clip properties is much increased if we're not showing the Media Pool

  2. DaVinci Resolve 18 has a bug where Start TC can't be set if the source viewer is currently showing the first frame of the clip. It works in the GUI but not via the API. It's a sneaky bug because it fails silently, SetClipProperty() still returns true. Since the Deliver page doesn't have a source viewer it works fine there.

Known issues
The full script linked below uses the same workaround of switching to the Deliver page while updating clip properties.

The bin traversal functionality and the ability to get the full path of each bin requires us to know the contents of the whole tree beforehand. Bin folders in DaVinci Resolve 18 doesn't have a GetParent() function so there's really no efficient way of finding the path to a folder.

Performance is reasonably good though. If you have like 10.000 clips in a project you'll have to wait a few seconds before you can click the Start button in the GUI. This is more noticeable when a project has just been loaded the first time. Also, Linux seems to excel here, I think LuaJIT is just faster on Linux overall.

If you know that project backups take a very long time on your system, you can increase the timeout threshold before it fails by changing script.default_timeout. It's set to 30 seconds by default.

Speaking of performance, I'm interested in feedback if you've tried this script on a project hosted in the Blackmagic Cloud.

One last thing, folders and clips returned from the API don't adhere to the sort order selected by the user. In fact, clips seem to return in random order at times. So I've just tried to make the best of it and provided a way of sorting clip lists by custom code as well.

Download
Set Timecode for Media Pool Clips.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:12 pm, edited 1 time in total.
Offline

AssistantEditor1

  • Posts: 108
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 28, 2023 10:13 pm

I have no immediate need for this but it’s great to know it exists!

Thanks Roger!
Offline

pantau000

  • Posts: 146
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 28, 2023 10:17 pm

I also appreciate this enormously. It's like a high-level course in scripting!
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 28, 2023 10:28 pm

Thanks. It's a bit daunting to have to make do with workarounds and also the limitation I imposed on myself to make all the scripts in this thread self-contained.

It makes the code a bit bloated but at the same time it's good to have made a bunch of scripts using the common functionality before committing parts of it to separate reusable modules. That way it gets properly vetted before it's too late.
Offline
User avatar

X-Raym

  • Posts: 139
  • Joined: Thu Apr 18, 2013 4:05 pm
  • Location: France
  • Real Name: Raymond Radet

Re: Creating Scripts for DaVinci Resolve

PostMon Mar 06, 2023 1:40 pm

Nice scripts!

If you want to take a look at some other user scripts, I also have a repository
  • https://github.com/X-Raym/DaVinci-Resolve-Scripts

As you are exploring Resolve Scripting you may have found some issues I also faced,
these feature requests may need your support:


The more scripters there will be, the more chance we have to get enhancements in Resolve Scripting I guess 8-)

Note:
Even though this is tab-delimited, Adobe calls it a CSV file (comma-separated values).

In this context, "c" refers to a more generic term, "characters", not comma. It Characters sepearated value, character being Tab in this context (never saw someone speak about a TSV file for Tab Separated Value for eg)
My DaVinci Resolve Scripts: https://github.com/X-Raym/DaVinci-Resolve-Scripts
Donation: https://paypal.me/extremraym
Offline
User avatar

SeldomSeenKid

  • Posts: 395
  • Joined: Mon May 31, 2021 1:16 pm
  • Location: Germany
  • Real Name: Michael Adrian

Re: Creating Scripts for DaVinci Resolve

PostTue Mar 07, 2023 1:59 pm


SetCurrentTimecode() has been added in v17.
Good judgement comes from experience. Experience comes from bad judgement.
# Threadripper 32 core / 160GB / RTX4000 8GB / WIN10 #
# BMCC / DVR17.4.6 Studio / Speed Editor / Tangent Ripple / X-Touch One / X-Touch mini / Space Explorer / 5.1 HDMI#
Offline
User avatar

X-Raym

  • Posts: 139
  • Joined: Thu Apr 18, 2013 4:05 pm
  • Location: France
  • Real Name: Raymond Radet

Re: Creating Scripts for DaVinci Resolve

PostTue Mar 07, 2023 2:33 pm

@SeldomSeenKid
Yes I know, I monitor API changes,

https://gist.github.com/X-Raym/2f2bf453 ... /revisions

it was the selected clip related functions which interest me there (get and set), but the forum thread title >I refered to hasnt been updated
My DaVinci Resolve Scripts: https://github.com/X-Raym/DaVinci-Resolve-Scripts
Donation: https://paypal.me/extremraym
Offline

jamesharding

  • Posts: 31
  • Joined: Sat Dec 07, 2013 3:54 pm

Re: Creating Scripts for DaVinci Resolve

PostFri Mar 10, 2023 3:56 pm

Hi there,

Thanks so much for the script. Unfortunately, my script is stuck on 'Please wait enumerating media pool bins'

I am running Resolve V17.4.6 and only have one clip in my bin

Any idea why it might be stuck at this point?

Thanks

James
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostFri Mar 10, 2023 4:12 pm

Hmm, the first thing that comes to mind is that the script is only tested on Resolve 18.

The clip in the bin, is it a "normal" video clip? Not a compound clip, timeline, Fusion composition or multicam clip or anything like that?
Offline

jamesharding

  • Posts: 31
  • Joined: Sat Dec 07, 2013 3:54 pm

Re: Creating Scripts for DaVinci Resolve

PostFri Mar 10, 2023 8:00 pm

Just a normal clip, I ran the script alone through the console and it worked fine, so I'm guessing it's the script with the gui that'd troublesome in 17. Worked a treat through through console.
Offline
User avatar

roger.magnusson

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

Fuse Plugins

PostThu Mar 16, 2023 7:43 pm

Today we'll do something different. A Fuse Plugin. There's a "Fuse Plugin Guide and Reference" included with DaVinci Resolve and Fusion Studio since version 18. You can also download it from https://documents.blackmagicdesign.com/UserManuals/Fusion_Fuse_SDK.pdf.

Unfortunately the documentation refers to examples that are supposed to be installed with the application but it seems they've forgotten to include them as I can't find them.

A Fuse is basically a Fusion tool you can write yourself using Lua. A "tool" in this context is typically a Fusion node. Fuses can handle different types of inputs/outputs, like images, numbers, text or more.

Installation
Fuses have to be installed in a specific folder in order for Resolve/Fusion to pick them up. After you've placed it in the correct folder, if Resolve/Fusion is already running you need to restart.

You should also be aware that Fuses don't travel with exported projects/comps. So if you need to use the project/comp on another machine you have to install the Fuse there as well.

macOS
In Finder, press Shift+Command+G to open "Go to Folder" and paste the path to open it.
Current user: ~/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Fuses
All users: /Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Fuses

Windows
In File Explorer, paste the path in the address bar to open it.
Current user: %AppData%\Blackmagic Design\DaVinci Resolve\Support\Fusion\Fuses
All users: %ProgramData%\Blackmagic Design\DaVinci Resolve\Fusion\Fuses

Linux
Current user: ~/.local/share/DaVinciResolve/Fusion/Fuses
All users: /opt/resolve/Fusion/Fuses (or /home/resolve/Fusion/Fuses)
Offline
User avatar

roger.magnusson

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

Number Formatter

PostThu Mar 16, 2023 7:45 pm

The type of Fuse we'll be making is a Modifier for Text. Its output will be compatible with any Text field in Fusion (including Text+ inserted via the Edit page).

The purpose of the Fuse is to provide the ability to format a numeric value in different ways as text. This is useful when you want to show a number that varies over time and isn't just a plain number but something like a price tag with a thousands separator, percentage or a number with leading zeros. As far as I know there's currently no built-in way to do that in Resolve other than with scripting.

Image

Making a user interface for a Fuse is different from what we're familiar with when writing scripts and using the UIManager. Instead, we add different types of input controls, configured using attributes. This post isn't an instruction in writing Fuses, more of an example as most of it is described in the Fuse documentation.

I'll just mention that the numeric value is formatted as a string using the string.format() function in Lua. It in turn uses the standard C printf function.

Download
Number Formatter.fuse

Follow the instructions for putting a Fuse in the Fuses folder here.

How to use it
Right-click on a Text field in a Fusion node/effect and select Number Formatter. If you're doing this on a Text+ title in the Edit page you don't have direct access to the Modifiers tab. To get to it click the little Fusion icon to the right of the Text+ header in the Inspector.

Now that you're on the Fusion page you can click the Modifiers tab where you'll find all the settings for this Modifier Fuse.

Image

As I said earlier, the point of all this is that we can now animate the value and keep the formatting. Like this:

Image
Yes, it's ugly. :lol: But it should illustrate the point of using data-driven animation with formatted numeric values.
Offline

Andy Mees

  • Posts: 3264
  • Joined: Wed Aug 22, 2012 7:48 am

Re: Creating Scripts for DaVinci Resolve

PostThu Mar 16, 2023 7:53 pm

Nice.
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostThu Mar 16, 2023 8:16 pm

Excellent!
No more messy and complicated expressions that I can’t read and usually can’t reuse.
Thanks.
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Mar 16, 2023 8:20 pm

Thanks. Yes, that can be a real pain. And the tiny Expression field adds insult to injury when you try to do anything that requires more than a few characters.
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostThu Mar 16, 2023 8:23 pm

It sure is tiny lol
I just keep copy pasting back and forth to a text editor, a real pain.
Thanks again for sharing.
Offline

derkassi

  • Posts: 1
  • Joined: Mon Mar 20, 2023 3:15 pm
  • Real Name: Karsten Silkenbäumer

Re: Creating Scripts for DaVinci Resolve

PostMon Mar 20, 2023 3:56 pm

Hi,
I'd like to follow along with scripting, but I'm already failing with setting it up properly.
I'm on a Mac running Venrura (13.2.1) and DaVinci Resolve 18.1.4 (build 9).

roger.magnusson wrote:To put a script in the Scripts menu, place the script file here:

macOS
In Finder, press Shift+Command+G to open "Go to Folder" and paste the path to open it.
Current user: ~/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility
All users: /Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility


Neither folder exists on my system, so I created "~/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility" on my own. Weird enough.
I placed a python script there, but nothing appears in the Workspace -> Scripts folder (after restarting DR).
I placed one of the lua scripts from this site there (Timeline Duration.lua), but nothing appears in the Workspace -> Scripts folder.

Seems like this information is taken from an outdated README file in the /Applications/DaVinci Resolve.app/Contents/Resources/Developer/Scripting folder, where also the app folder is mentioned in a wrong way.

Any idea on how to fix it and get started?

Thanks
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostWed Mar 22, 2023 5:34 pm

Are you using DaVinci Resolve downloaded from the Blackmagic Design web site or are you using the version from the Mac App Store? You shouldn't have to create any folders. I suppose there might be a difference in how the folders are structured in the Mac App Store version but it's not something I've heard about before.

Regarding Python scripts they won't work at all until you install a compatible official release from https://www.python.org/downloads/. Try something simple in the Workspace > Console window first, so you know that it's working.
Offline

ogurets13

  • Posts: 2
  • Joined: Tue Nov 08, 2022 1:03 pm
  • Real Name: Mikhail Frantskevich

Re: Creating Scripts for DaVinci Resolve

PostSat Apr 01, 2023 9:56 pm

Man, the script for setting Source Timeline to zero worked great for me and is absolutely indispensable. Had to make my previous project in Final Cut just because I missed this feature. Thank you!
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostMon Apr 03, 2023 10:33 pm

Glad to hear it! Thanks.
Offline
User avatar

Igor Riđanović

  • Posts: 1605
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Creating Scripts for DaVinci Resolve

PostTue Apr 04, 2023 10:23 pm

pantau000 wrote:
roger.magnusson wrote:For a Lua script you need to use the colon symbol when invoking the Resolve API methods. Like this:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem(marker_frame)
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

But note that GetMediaPoolItem() doesn't take any parameters.

Thanks, but this is all still a mystery to me...
Would I have to include this line to get the item?
Code: Select all
timelineitem = timeline.GetCurrentVideoItem()

And then:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem()
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)


Yes. You have to create the instance of the timeline item before you can use it to get the media pool item. Watch for the colons/periods. Lua uses ":" while Python uses ".".

Also check the spelling of the timelineItem. Make sure it's consistent through all the lines of code, including the capitalization.
www.metafide.com - DaVinci Resolve™ Apps
Offline

rubefink

  • Posts: 64
  • Joined: Mon Nov 25, 2019 8:33 pm
  • Real Name: Reuben Finkelstein

Re: Creating Scripts for DaVinci Resolve

PostSun Apr 09, 2023 8:44 am

I'm completely new at this so forgive my ignorance but I'm getting errors each time I try to run any script that interacts with the API. I'm trying to run an example script that comes with davinci named "get_project_information.py"

I copy and paste the below script into the console in the py3 section but I keep getting this error:

Traceback (most recent call last):
File "<nofile>", line 9, in <module>
ModuleNotFoundError: No module named 'python_get_resolve'


Can you let me know what I might be doing wrong or am I missing some setup to allow davinci to use scripting with the API?

Below is the script:

-----------------

#!/usr/bin/env python

"""
Example DaVinci Resolve script:
Display project information: timeline, clips within timelines and media pool structure.
Example usage: 5_get_project_information.py
"""

from python_get_resolve import GetResolve

def DisplayTimelineTrack( timeline, trackType, displayShift ):
trackCount = timeline.GetTrackCount(trackType)
for index in range (1, int(trackCount) + 1):
print(displayShift + "- " + trackType + " " + str(index))
clips = timeline.GetItemListInTrack(trackType, index)
for clip in clips:
print(displayShift + " " + clip.GetName())
return

def DisplayTimelineInfo( timeline, displayShift ):
print(displayShift + "- " + timeline.GetName())
displayShift = " " + displayShift
DisplayTimelineTrack(timeline , "video", displayShift)
DisplayTimelineTrack(timeline , "audio", displayShift)
DisplayTimelineTrack(timeline , "subtitle", displayShift)
return

def DisplayTimelinesInfo( project ):
print("- Timelines")
timelineCount = project.GetTimelineCount()

for index in range (0, int(timelineCount)):
DisplayTimelineInfo(project.GetTimelineByIndex(index + 1), " ")
return

def DisplayFolderInfo( folder, displayShift ):
print(displayShift + "- " + folder.GetName())
clips = folder.GetClipList()
for clip in clips:
print(displayShift + " " + clip.GetClipProperty("File Name"))

displayShift = " " + displayShift

folders = folder.GetSubFolderList()
for folder in folders:
DisplayFolderInfo(folder, displayShift)
return

def DisplayMediaPoolInfo( project ):
mediaPool = project.GetMediaPool()
print("- Media pool")
DisplayFolderInfo(mediaPool.GetRootFolder(), " ")
return

def DisplayProjectInfo( project ):
print("-----------")
print("Project '" + project.GetName() +"':")
print(" Framerate " + str(project.GetSetting("timelineFrameRate")))
print(" Resolution " + project.GetSetting("timelineResolutionWidth") + "x" + project.GetSetting("timelineResolutionHeight"))

DisplayTimelinesInfo(project)
print("")
DisplayMediaPoolInfo(project)
return

# Get currently open project
resolve = GetResolve()
projectManager = resolve.GetProjectManager()
project = projectManager.GetCurrentProject()

DisplayProjectInfo(project)
Offline

Steve Swisz

  • Posts: 66
  • Joined: Tue Aug 11, 2015 1:51 am

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 13, 2023 12:23 am

Hey Guys,
I stepped back into this with version 18, I am missing something with the API updated to version 18.1.3.
I am using Python 3.6, goal is to import Folders and maintain all Directories when brought into the media pool.
I can bring objects in all day long but cannot find the method or a simple way to maintain the directories.

Thanks
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 13, 2023 3:40 pm

rubefink wrote:I'm completely new at this so forgive my ignorance but I'm getting errors each time I try to run any script that interacts with the API. I'm trying to run an example script that comes with davinci named "get_project_information.py"

I copy and paste the below script into the console in the py3 section but I keep getting this error:

Traceback (most recent call last):
File "<nofile>", line 9, in <module>
ModuleNotFoundError: No module named 'python_get_resolve'


Can you let me know what I might be doing wrong or am I missing some setup to allow davinci to use scripting with the API?

Which operating system? Have you set the environment variables mentioned in the readme? I haven't looked at those Python examples in a while, but does it work if you put them in the appropriate Scripts folder and run the from the Workspace menu? Those examples require the python_get_resolve.py module so you would have to copy it to the appropriate place too.
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 13, 2023 3:44 pm

Steve Swisz wrote:I can bring objects in all day long but cannot find the method or a simple way to maintain the directories.


Unfortunately, I think currently the only way is to make your own method to recreate the behavior of the Create Bins option in the GUI. Not a very good option considering the bins will keep refreshing on every scripted action, making it a pretty slow process.
Offline

rubefink

  • Posts: 64
  • Joined: Mon Nov 25, 2019 8:33 pm
  • Real Name: Reuben Finkelstein

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 13, 2023 9:03 pm

[/quote]
Which operating system? Have you set the environment variables mentioned in the readme? I haven't looked at those Python examples in a while, but does it work if you put them in the appropriate Scripts folder and run the from the Workspace menu? Those examples require the python_get_resolve.py module so you would have to copy it to the appropriate place too.[/quote]

I’m on Ventura MAC. Moving those scripts did work thanks. Can you elaborate on why pasting the code into the console didn’t work? Also has anyone here had success with coding using ChatGPT?
Offline
User avatar

roger.magnusson

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

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 13, 2023 10:02 pm

The issue is that the resolve module can't be found if it's not in a folder where the Python interpreter or the script that invokes it knows to look. I have very little experience with Python so I can't really elaborate more than that. But it's clear to me from the error message that that's the issue.

Regarding ChatGPT, it can be really helpful for very specific small coding tasks, especially GPT-4. GPT3.5 is pretty useless for coding in my opinion. Even so, you really have to know more than the basics in order to guide it to create functional and well made code.
Offline
User avatar

iddos-l

  • Posts: 799
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostFri Apr 14, 2023 5:35 am

Regarding Python from the console.
You don't need to instantiate the Resolve object; it's already there (in V18 at least).
As long as Python is correctly set in your system environment, you can simply call Resolve.
So, you don't need to use the get_resolve module.
Just start using the Resolve object like:
'projectManager = resolve.GetProjectManager()'
Offline

Steve Swisz

  • Posts: 66
  • Joined: Tue Aug 11, 2015 1:51 am

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 20, 2023 12:30 am

Mac Big Sur 11.6 - Tested this on 18 and the 18.5 Beta, working but have return errors in the console.

Code: Select all
import sys
import os
import tkinter as tk
from tkinter import filedialog

# Set Resolve Module Path:
sys.path.append('/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules')

import DaVinciResolveScript as bmd

resolve = bmd.scriptapp('Resolve')
pm = resolve.GetProjectManager()
proj = pm.GetCurrentProject()
mp = proj.GetMediaPool()

# Popup to choose the folder to import
root = tk.Tk()
root.withdraw()
folder_path = filedialog.askdirectory(title='Choose Folder to Import')

# Create the new bin in the media pool
root_folder = mp.GetRootFolder()
new_bin = mp.AddSubFolder(root_folder, os.path.basename(folder_path))

# Get the MediaStorage object
media_storage = resolve.GetMediaStorage()

# Add the items in the chosen directory to the new bin in the media pool
items = media_storage.GetFileList(folder_path)
media_pool_items = media_storage.AddItemListToMediaPool(items)
for item in media_pool_items:
    new_bin.AddItem(item)
[code][/code]
Offline
User avatar

Robert Niessner

  • Posts: 5031
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 20, 2023 5:46 pm

Resolve 18.5 Beta has now added a few improvements to the scripting API:

— Scripting API support to import and export DRT and DRB files.
— Scripting API support to load data burn presets.
— Scripting API support to get node label.
— Scripting API support to apply ARRI CDL and LUT to a clip.
— Scripting API support for querying and setting clip enabled state.
— Supported containers for selected codecs are now listed in the encode API.
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline

Steve Swisz

  • Posts: 66
  • Joined: Tue Aug 11, 2015 1:51 am

Re: Creating Scripts for DaVinci Resolve

PostFri Apr 21, 2023 6:58 pm

Hey Team,
I am looking at trying to bring back an old option Resolve had in version 16, Media Management you could MOVE media, and this was extremely useful to me.
I was hoping I could create a Python script that would let me use the current Media Manage Copy, then have a post script run once the media was moved to new location to DELETE the files in the original path.

If any of you could help out with this it would be greatly appreciated.
PreviousNext

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], ja_saldivar, Johannes Jonsson, kfriis and 141 guests