Jump to: Board index » General » Fusion

Script To Insert Macro

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

Nick Verlinden

  • Posts: 166
  • Joined: Wed Aug 12, 2015 11:08 am

Script To Insert Macro

PostSun Jun 17, 2018 3:52 pm

Hi,

Is it possible to insert a Macro after a specific tool from a script? For instance, If I do a comp:FindTool("Blur1"), can I insert a custom Macro after that (Like when you would right click the node and choose "Insert Tool > Macros > [macro name here]"? I have looked through the documentation and googled quite a while but can't seem to find the answer. Any help would be greatly appreciated!

Kind regards,
Nick
macOS 10.13.2 High Sierra
Core i9 7920X, 32GB RAM
GTX 1080 Ti 11GB
Blackmagic DeckLink Mini Monitor 4K
Blackmagic URSA Mini Pro
Blackmagic Pocket Cinema Camera
Blackmagic DaVinci Resolve Studio 15
Offline
User avatar

Andrew Hazelden

  • Posts: 536
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: Script To Insert Macro

PostSun Jun 17, 2018 8:00 pm

Nick Verlinden wrote:I have looked through the documentation and googled quite a while but can't seem to find the answer. Any help would be greatly appreciated!


Hi Nick.

I wrote a new tutorial on the Steakunderwater website today that explores several different ways to use Lua scripting to add a macro node to a comp and connect it to the currently selected node:

Using a Script to Add Macros to a Comp
https://www.steakunderwater.com/wesuckl ... 822#p17822
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline

Nick Verlinden

  • Posts: 166
  • Joined: Wed Aug 12, 2015 11:08 am

Re: Script To Insert Macro

PostMon Jun 18, 2018 11:12 am

Hi Andrew,

Wow, that is exacty ywhat I need, thank you for taking the time to research and write this. I have implemented this in a script to automatically add a macro to the fusion comp of all clips on a specific video track in DaVinci resovle beta 15. Once I fine tuned it a little, I will check out how to publish it to Reactor. I hope that in one of the net betas a new API function is available to get the selected clips on a timeline, this way the macro can be adapted to apply to the selected clips.

I'm just currently looking at a way to detect if the macro has already been inserted, so that it does not get inserted twice when recalling the script when clips are added to a video track. I think the best way would probably be, parse the filename of the macro, remove the spaces and add 1 to the end of the name.

Kind Regards,
Nick
macOS 10.13.2 High Sierra
Core i9 7920X, 32GB RAM
GTX 1080 Ti 11GB
Blackmagic DeckLink Mini Monitor 4K
Blackmagic URSA Mini Pro
Blackmagic Pocket Cinema Camera
Blackmagic DaVinci Resolve Studio 15
Offline
User avatar

Andrew Hazelden

  • Posts: 536
  • Joined: Sat Dec 06, 2014 12:10 pm
  • Location: West Dover, Nova Scotia, Canada

Re: Script To Insert Macro

PostMon Jun 18, 2018 11:49 am

Nick Verlinden wrote:I'm just currently looking at a way to detect if the macro has already been inserted, so that it does not get inserted twice when recalling the script when clips are added to a video track.


The following code scans the current Fusion comp to look for all of the GroupOperator and MacroOperator node RegIDs. Then it looks up their node names:

Code: Select all
--[[--
Scan comp for macro nodes - 1.0 2018-06-18
By Andrew Hazelden <andrew@andrewhazelden.com>
--]]--

-- Should only the currently selected nodes be displayed
local showSelected = false

print('[Listing Macros]')

-- List the macros that are stored as groups
print('\n[GroupOperator Based Macros]')
local toollist1 = comp:GetToolList(showSelected, 'GroupOperator')
for i, tool in ipairs(toollist1) do
   nodeID = tool:GetAttrs().TOOLS_RegID
   nodeName = tool:GetAttrs().TOOLS_Name
   print('\t[' .. nodeName .. ' Macro] ' ..  nodeID)
end

-- List the macros that have their controls exposed but the group expandable option disabled
print('\n[MacroOperator Based Macros]')
local toollist2 = comp:GetToolList(showSelected, 'MacroOperator')
for i, tool in ipairs(toollist2) do
   nodeID = tool:GetAttrs().TOOLS_RegID
   nodeName = tool:GetAttrs().TOOLS_Name
   print('\t[' .. nodeName .. ' Macro] ' ..  nodeID)
end




This gives you an output in the Console that looks like this:

Code: Select all
[Listing Macros]

[GroupOperator Based Macros]
   [Z360Extract Macro] GroupOperator
   [Angular2Equirectangular Macro] GroupOperator
   [MayaBackgroundGradientEquirectangular Macro] GroupOperator
   [Group1 Macro] GroupOperator

[MacroOperator Based Macros]
   [Z360Render_1 Macro] MacroOperator
Mac Studio M2 Ultra / Threadripper 3990X | Fusion Studio 18.6.4 | Kartaverse 6
Offline

Nick Verlinden

  • Posts: 166
  • Joined: Wed Aug 12, 2015 11:08 am

Re: Script To Insert Macro

PostWed Jun 20, 2018 8:46 pm

Thanks Andrew, you have been a very big help for me!
macOS 10.13.2 High Sierra
Core i9 7920X, 32GB RAM
GTX 1080 Ti 11GB
Blackmagic DeckLink Mini Monitor 4K
Blackmagic URSA Mini Pro
Blackmagic Pocket Cinema Camera
Blackmagic DaVinci Resolve Studio 15
Offline

arlo247

  • Posts: 3
  • Joined: Thu Jan 17, 2019 9:28 pm
  • Real Name: Richard London

Re: Script To Insert Macro

PostThu Jan 17, 2019 9:38 pm

Hi,

I’m trying to use Python to add a Fusion macro to a composition. I’ve tried the methods suggested here, but without success. Adding simple tools such as Merge and Background work fine, but macros, both my own and Fusion titles such as Title Center Reveal will not be placed in the comp. No error message appears in the console. Any advice would be appreciated. Code below.

Thanks.
Code: Select all
clips = timeline.GetItemsInTrack("video", 1) # Use video track 1

for clipIdx in clips:
    clipCount = clipCount + 1
    clipColor=clips[clipIdx].GetClipColor()
    if clipColor=="Navy":
        print ("Clip color: " + clipColor)
        # Importing a comp results in a black screen for that timeline item.  Fusion comp seems to overlay it with black
        #thisComp = clips[clipIdx].ImportFusionComp('C:\\Program Files\\DaVinci Resolve\\Fusion\\Templates\\Edit\\Titles\\Title Center Reveal.setting')
        #thisComp.mainText.StyledText[0] = "Replay: " + str(datetime.datetime.now())[:-7]
        thisComp = clips[clipIdx].GetFusionCompByName("Composition 1")
        thisComp.SetActiveTool(thisComp.FindTool("MediaIn1"))
        thisComp.AddToolAction("Merge") # Merge is the name of the tool. No problem adding a Merge to the comp.
        thisComp.SetActiveTool(thisComp.FindTool("Merge1")) # Merge1 is the name of the instance of the Merge tool

        ######## The AddTools and Pastes below don't work with macros
        thisComp.AddTool("TTScoreboard")
        #thisComp.AddToolAction("Transform") # No problem adding a Transform to the comp
        #thisComp = clips[clipIdx].ImportFusionComp('C:\\Users\\rlondon\\AppData\\Roaming\\Blackmagic Design\\DaVinci Resolve\\Fusion\\Macros\\TTScoreBoard.setting')
        # Load the macro by reading the file from disk and paste it into the comp
        #thisComp.Paste(bmd.readfile(thisComp.MapPath("Macros:/RLCentitle.setting")))
        #thisComp.Paste(bmd.readfile(thisComp.MapPath("C:\\Users\\rlondon\\AppData\\Roaming\\Blackmagic Design\\DaVinci Resolve\\Fusion\\Macros\\TTScoreBoard.setting")))
        thisComp.Paste(bmd.readfile(thisComp.MapPath("C:\\Program Files\\DaVinci Resolve\\Fusion\\Templates\\Edit\\Titles\\Title Center Reveal.setting")))
        x = bmd.readfile(thisComp.MapPath("C:\\Program Files\\DaVinci Resolve\\Fusion\\Templates\\Edit\\Titles\\Title Center Reveal.setting"))
        print("Content read from file: Title: " + str(x)) # No problem reading the file

        macro = bmd.readfile(thisComp.MapPath("Macros:/RLCentitle.setting"))
        print("Content read from file: Macro: " + str(macro)) # No problem reading the file

print("Clips found: "+str(clipCount))
print("Done.")
Resolve 15.2.1
ASUS x99 Pro, water-cooled i7 5930k, 32gb DDR4 2400, Windows 8.1 Pro
NVidia GTX 1080 Ti 11gb
OS: Intel 750 NVME SSD
Cache: Samsung 850 Pro
Target: Samsung 850
Sources: 1gb LAN, OS drive

Return to Fusion

Who is online

Users browsing this forum: No registered users and 23 guests