Page 1 of 1

Script To Insert Macro

PostPosted: Sun Jun 17, 2018 3:52 pm
by Nick Verlinden
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

Re: Script To Insert Macro

PostPosted: Sun Jun 17, 2018 8:00 pm
by Andrew Hazelden
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

Re: Script To Insert Macro

PostPosted: Mon Jun 18, 2018 11:12 am
by Nick Verlinden
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

Re: Script To Insert Macro

PostPosted: Mon Jun 18, 2018 11:49 am
by Andrew Hazelden
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

Re: Script To Insert Macro

PostPosted: Wed Jun 20, 2018 8:46 pm
by Nick Verlinden
Thanks Andrew, you have been a very big help for me!

Re: Script To Insert Macro

PostPosted: Thu Jan 17, 2019 9:38 pm
by arlo247
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.")