Resolve Scripting Essentials

User avatar
SirEdric
Fusionator
Posts: 1237
Joined: Tue Aug 05, 2014 10:04 am
Been thanked: 113 times
Contact:

Re: Resolve Scripting Essentials

#16

Post by SirEdric » Wed Apr 11, 2018 10:58 pm

Greg Bovine wrote:
Wed Apr 11, 2018 1:54 pm
fu:ToggleUtility('FBXImport')
Brilliant!
Now if one only could do something like fu:ToggleUtility('FBXImport', 'p:\ath\to\file.obj', autoImport = true)

Nick Verlinden
Posts: 8
Joined: Thu Apr 12, 2018 5:29 am

Re: Resolve Scripting Essentials

#17

Post by Nick Verlinden » Thu Apr 12, 2018 5:54 am

When I try to call the Resolve function inside the console from the Fusion page, it does not return anything. Is anybody else experiencing this? I tested this on both Windows and macOS in the public beta "15.0.0B.030". I can't get any of the example resolve scripts from this thread to work because the Resolve function does not return anything.

Lua> local resolve = Resolve()
Lua> dump(resolve)
nil

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

Local Variable Scope in the Console

#18

Post by Greg Bovine » Thu Apr 12, 2018 6:12 am

Nick Verlinden wrote:
Thu Apr 12, 2018 5:54 am
When I try to call the Resolve function inside the console from the Fusion page, it does not return anything. Is anybody else experiencing this? I tested this on both Windows and macOS in the public beta "15.0.0B.030". I can't get any of the example resolve scripts from this thread to work because the Resolve function does not return anything.

Lua> local resolve = Resolve()
Lua> dump(resolve)
nil
Hi Nick.

Well...Yeah. It's not a Resolve issue in this case. You will have to check your Lua code there and change it a bit. ;)

Single line commands run one-at-a-time from the Console window that have a "local" variable scope are destroyed immediately after they are run since you told them to be "local"... You can either write that code as a multiline block of text in a text editor and paste it into the Console window for testing, or take off the word "local" on the variable.

Exploring Variable Scope

An example of this Lua local scope variable effect in the Console is if I was to do this using two lines of text entered one at a time:

Code: Select all

Lua> local name = "Bob"
Lua> print(name)
-- Result: nil
vs doing it as a single block of text entered at once:

Code: Select all

Lua> local name = "Bob"
print(name)
-- Result: Bob
So with that point taken care of let's try using the Resolve API function again and see if both of these code chunks work for you:

Code: Select all

dump(Resolve())
or

Code: Select all

resolve = Resolve()
dump(resolve)
Why Use Local Variables Though?

The reason you would want to use local for variables in a .lua script that is being run from a file off disk is you can access remote systems with resolve scripting using fuscript. This means the "resolve" variable might not be referring to your current desktop system but could be accessed inside a separate function or a loop to access many remote computer sessions at the same time.

Local variable scope would allow different functions in your code to have the same variable name "resolve" and be able to track the value uniquely inside each function. This would let you use Resolve's newly added UI Manager GUI system to make your own Resolve remote control tool.

For connecting to the local Resolve session from Lua you could also use a command like this:

Code: Select all

resolve = bmd.scriptapp("Resolve", "localhost")
If you have the Resolve preferences set to allow for network access from a script then you could use a command like this to do remote control.

(In this case the numbers in quotes in the code below would be the IP address or host name of the remote Resolve system you want to connect to. The remote system has to be running an already active copy of the Resolve GUI for this code to work.)

Code: Select all

resolve = bmd.scriptapp("Resolve", "10.20.30.15")

Nick Verlinden
Posts: 8
Joined: Thu Apr 12, 2018 5:29 am

Re: Resolve Scripting Essentials

#19

Post by Nick Verlinden » Thu Apr 12, 2018 6:23 am

Hi Greg,

Thank you for your quick reply. Oh I see, my mistake. Mostly I develop Javascript, and am not familiar with the scoping of Lua, I should read up on that, thank you! However, the problem is not solved. Appearantly there is already a new build "15.0.0B.032" wich I just installed. But still get the same result:

Lua> dump(Resolve())
nil

EDIT: when i try this on macOS with "15.0.0B.030", I do get the expected result. the only difference is that on macOS I'm running DaVinci Resolve Studio, whereas on Windows, i'm running the free version. Could this be a limitation that in the free version we only have access to the Fusion API and not the Resolve API?

Greetz!
Nick

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

External Scripting Using Preference

#20

Post by Greg Bovine » Thu Apr 12, 2018 6:26 am

Hi Nick.

It works fine for me with Resolve Studio 15 Beta 30 on macOS:

resolve 15 beta 30 on macos.png

Try opening the Resolve preferences and switch to the System > Configuration view. What is your "External Scripting Using" control set to?

resolve-prefs-external-scripting-using.png

Do you have any local firewall rules active on your system that might be blocking inter-application communication such as stopping Resolve from connecting to the fuscript process on the same system?
You do not have the required permissions to view the files attached to this post.

Nick Verlinden
Posts: 8
Joined: Thu Apr 12, 2018 5:29 am

Re: Resolve Scripting Essentials

#21

Post by Nick Verlinden » Thu Apr 12, 2018 6:32 am

It seems that the free version of Resolve removes this option from the preferences because I can see it on macOS but not on Windows, which hints that the Resolve API is unavailable in the free version, and you can only do Fusion scripting in the free version. I also saw this referenced in the Resolve vs Resolve Studio comparison document on the BMD website, it clearly states that scripting is unavailable in the free version. But I found it confusing because the Fusion console is available in the free version. At least now we know :-)

Thank you very much for this forum thread by the way, it saves me a lot of research work :-)

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

Re: Resolve Scripting Essentials

#22

Post by Greg Bovine » Thu Apr 12, 2018 6:35 am

Thanks for your reply. I can see how Resolve automation scripting might be a feature they hold back for Resolve Studio users as it would be worth paying for.

In Fusion (Free) they blocked out access to the fuscript external process so only Fusion Studio users could do some types of automation such as command line scripting with "fuscript.exe".

Nick Verlinden
Posts: 8
Joined: Thu Apr 12, 2018 5:29 am

Re: Resolve Scripting Essentials

#23

Post by Nick Verlinden » Thu Apr 12, 2018 6:38 am

I totally agree, it is mostly an Enterprise feature and the cost of a license is nothing compared to that of Media Composer.

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

Resolve Dummy Node Lister Script

#24

Post by Greg Bovine » Fri Apr 13, 2018 9:59 am

loader-node-missing-warning.png
Resolve uses a new MediaIn/MediaOut node analogy to access media in a Fusion page composite. If you are importing Fusion .comp files into Resolve you will start to have inactive Loader/Saver nodes pile up that you can't do much with.

When Loader/Saver nodes are imported they are deactivated and the nodes have a dark grey node color in the Flow (Nodes view).

resolve-loader-nodes-in-comp.png

This Lua script allows you to scan the current Resolve Fusion page comp for inactive Loader/Saver nodes by looking for a node Registry ID type of "Dummy". This Registry ID type is used for Loader/Saver nodes, or anything else that is unrecognized by Fusion.

Resolve-Dummy-Node-Lister.png
Code: [Select all] [Expand/Collapse] [Download] (ResolveDummyNodeLister.lua)
  1. -- List all of the "Dummy" missing nodes in a Resolve Fusion page comp
  2. -- This dummy Registry ID type is used for Loader/Saver nodes or anything else that is unrecognized.
  3.  
  4. print('\n---------------------------------')
  5. print('Resolve Fusion Dummy Node Scanner')
  6. print('---------------------------------\n')
  7.  
  8. -- Scan all Dummy nodes in the comp
  9. tools = comp:GetToolList(false, 'Dummy')
  10. print(string.format('[Dummy Nodes] %d Found\n\n', #tools))
  11. for i, val in ipairs(tools) do
  12.     -- Check the "Dummy" node name
  13.     nodeName = tostring(val:GetAttrs().TOOLS_Name)
  14.     regID = tostring(val:GetAttrs().TOOLS_RegID)
  15.     print(string.format('[%d] [Node] %s [ID] %s\n', i, nodeName, regID))
  16.    
  17.     -- List the node's input settings
  18.     for i, inp in pairs(val:GetInputList()) do
  19.         inputID = tostring(inp:GetAttrs().INPS_ID)
  20.         inputName = tostring(inp:GetAttrs().INPS_Name)
  21.         inputDataType = tostring(inp:GetAttrs().INPS_DataType)
  22.         print(string.format('\t[Registry ID] %26s\t[Data Type] %10s', inputName, inputDataType))
  23.     end
  24.     print('\n--------------------------------------------------------------------------------\n')
  25. end
  26.  
  27. print('[Done]')
  28.  


Code: [Select all] [Expand/Collapse] [Download] (ResolveDummyNodeLister Output.txt)
  1. --------------------------------
  2. Resolve Fusion Dummy Node Scanner
  3. ---------------------------------
  4.  
  5. [Dummy Nodes] 1 Found
  6.  
  7.  
  8. [1] [Node] Loader5 [ID] Dummy
  9.  
  10.     [Registry ID]          Gamut.SLogVersion    [Data Type]     Number
  11.     [Registry ID]                      Blend    [Data Type]     Number
  12.     [Registry ID]  Process when Blend is 0.0    [Data Type]     Number
  13.     [Registry ID]                Process Red    [Data Type]     Number
  14.     [Registry ID]              Process Green    [Data Type]     Number
  15.     [Registry ID]               Process Blue    [Data Type]     Number
  16.     [Registry ID]              Process Alpha    [Data Type]     Number
  17.     [Registry ID]                               [Data Type]     Number
  18.     [Registry ID]        Apply Mask Inverted    [Data Type]     Number
  19.     [Registry ID]           Multiply by Mask    [Data Type]     Number
  20.     [Registry ID]                   Fit Mask    [Data Type]       FuID
  21.     [Registry ID]                               [Data Type]     Number
  22.     [Registry ID]                    Channel    [Data Type]     Number
  23.     [Registry ID]                        Low    [Data Type]     Number
  24.     [Registry ID]                       High    [Data Type]     Number
  25.     [Registry ID]                 Clip Black    [Data Type]     Number
  26.     [Registry ID]                 Clip White    [Data Type]     Number
  27.     [Registry ID]                               [Data Type]     Number
  28.     [Registry ID]                 Use Object    [Data Type]     Number
  29.     [Registry ID]               Use Material    [Data Type]     Number
  30.     [Registry ID]              Correct Edges    [Data Type]     Number
  31.     [Registry ID]                  Object ID    [Data Type]     Number
  32.     [Registry ID]                Material ID    [Data Type]     Number
  33.     [Registry ID]                               [Data Type]     Number
  34.     [Registry ID]                Motion Blur    [Data Type]     Number
  35.     [Registry ID]                    Quality    [Data Type]     Number
  36.     [Registry ID]              Shutter Angle    [Data Type]     Number
  37.     [Registry ID]                Center Bias    [Data Type]     Number
  38.     [Registry ID]              Sample Spread    [Data Type]     Number
  39.     [Registry ID]        Frame Render Script    [Data Type]     Number
  40.     [Registry ID]        Frame Render Script    [Data Type]       Text
  41.     [Registry ID]       Start Render Scripts    [Data Type]     Number
  42.     [Registry ID]        Start Render Script    [Data Type]       Text
  43.     [Registry ID]         End Render Scripts    [Data Type]     Number
  44.     [Registry ID]          End Render Script    [Data Type]       Text
  45.     [Registry ID]                   Comments    [Data Type]     Number
  46.     [Registry ID]                   Comments    [Data Type]       Text
  47.     [Registry ID]                Effect Mask    [Data Type]       Mask
You do not have the required permissions to view the files attached to this post.

RBemendo
Fusioneer
Posts: 129
Joined: Fri Dec 12, 2014 11:32 am
Been thanked: 2 times

Re: Resolve Scripting Essentials

#25

Post by RBemendo » Fri Apr 13, 2018 2:13 pm

Awesome stuff Greg!!

There's so much to read through on this thread, I can't quite wrap my head around all of it yet. Thank you for your efforts!!

BigRoyNL
Fusioneer
Posts: 71
Joined: Wed Oct 29, 2014 5:51 am
Been thanked: 6 times

Re: Resolve Scripting Essentials

#26

Post by BigRoyNL » Sun Apr 15, 2018 7:50 am

SirEdric wrote:
Wed Apr 11, 2018 10:58 pm
Now if one only could do something like fu:ToggleUtility('FBXImport', 'p:\ath\to\file.obj', autoImport = true)
Amen to that! :) Still unfortunate there seems to be no way to access that.

User avatar
Igor Ridanovic
Posts: 9
Joined: Mon Apr 16, 2018 11:17 pm
Location: Los Angeles
Contact:

Re: Resolve is just a GUI to an Sqlite3 Media Database

#27

Post by Igor Ridanovic » Mon Apr 16, 2018 11:38 pm

Code: Select all

sqlite3 "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Resolve Disk Database/Resolve Projects/Users/guest/Projects/Ozo Stitch/Project.db" ".header on" ".mode column" "SELECT ProjectName FROM SM_Project;" "SELECT Name, MediaFilePath, Start, Duration FROM Sm2TiItem WHERE DbType = 'Sm2TiVideoClip';"

Amazing work Greg.

I've been externally querying Resolve DB using Psql. It requires the user name and password. Your CLI Sqlite3 example above uses no authentication. How does it connect to the DB? Does your example work only on the host that's running the PostgreSQL server?

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

Re: Resolve is just a GUI to an Sqlite3 Media Database

#28

Post by Greg Bovine » Tue Apr 17, 2018 10:02 am

Igor Ridanovic wrote:
Mon Apr 16, 2018 11:38 pm
How does it connect to the DB? Does your example work only on the host that's running the PostgreSQL server?
Hi Igor.

My focus was on providing Fusion Studio (Standalone) users with the knowledge and tools to be able to use the Resolve Fusion page. The sqlite3 related code examples were simply reading the Resolve project's database "Project.db" file that are stored locally on disk inside the Resolve user preferences "Resolve Disk Database/Resolve Projects/Users/" sub-folders.

User avatar
Igor Ridanovic
Posts: 9
Joined: Mon Apr 16, 2018 11:17 pm
Location: Los Angeles
Contact:

Re: Resolve Scripting Essentials

#29

Post by Igor Ridanovic » Tue Apr 17, 2018 10:48 am

Of course. Looking for the authentication in your argument string I failed to acknowledge the clearly spelled out path to the Disk Database. The answer was in plain sight. Thanks. It's possible to achieve similar functionality by using Psql in shared PostgreSQL environments.

User avatar
Greg Bovine
Double M
Posts: 129
Joined: Fri Feb 02, 2018 6:07 am
Location: Oslo, Norway
Been thanked: 36 times
Contact:

MediaOutUltra Macro for Resolve

#30

Post by Greg Bovine » Wed Apr 18, 2018 6:29 am

Here is an early access copy of the MediaOutUltra macro that is part of the upcoming "Reactor Essentials" atom package.

This node extends the features offered by Resolve's standard "MediaOut" node using custom UserControls based Lua script additions. This macro cannot be used in Fusion Standalone since it relies on a MediaIn node being present in the compositing environment. No tech support will be provided for this macro and it is provided on an **as is** basis.

The "MediaOutUltra" macro provides a way to render a Resolve 15 Fusion comp to disk directly using the left or right viewer window graphics context. This allows you to bypass Resolve's Deliver page and render multi-channel EXR image sequences, along with other image formats to disk while staying inside of the Fusion page.


The macro renders the active Fusion page's renderable frame range using the current start frame and end frame range values.


Screenshot

MediaOutUltra.png

Macro Controls

Render View

The Render View control lets you specify if the Fusion page "Right View" or "Left View" viewport window is used when saving the imagery to disk.

Filename

The Filename field expects the image filepath to be formatted like "/Volumes/Media/name.0000.ext". The "name.0000.ext" part of the filename is required due to a Lua pattern based filename replacement approach being is used to save the image sequence to disk.

You can use Fusion page based PathMaps for the output folder location but "Comp:/" is not a valid option since Resolve uses a database to hold a project which means it doesn't store any files in a composite centric folder.

Padding

The Padding control is what defines the number of leading zero digit padding characters added to the frame number in the filename.

Sequence Offset

The Sequence Offset command allows you to shift the frame number value +/- in frames from the current Resolve timeline value. As an example this control would allow you to move the rendered image sequence to start numbering the frames at 1001 while Resolve has regular timeline starting value of 0.

Purge Cache

The Purge Cache checkbox should generally be left off. This control is only there for Windows users to experiment with if they are using a lot of Fuses and CustomTool nodes in their Fusion page composites and start running into memory caching problems. This control has not been tested extensively since the MediaOutUltra macro was written and tested primarily on macOS.

Render Through Viewer

To launch the render click the "Render Through Viewer" button while viewing the output of this node in your viewer window.

Open Containing Folder

The "Open Containing Folder" button allows you to quickly jump to the output folder.

Download

MediaOutUltra.setting

Installation


Install this macro by copying the file to the Resolve user preferences PathMap folder location of:

Code: Select all

Macros:/IO/MediaOutUltra.setting
You do not have the required permissions to view the files attached to this post.