Auto applying a template between loader and saver

Moderator: SecondMan

User avatar
Midgardsormr
Fusionator
Posts: 1216
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 3
Location: Los Angeles, CA, USA
Been thanked: 96 times
Contact:

Re: Auto applying a template between loader and saver

#31

Post by Midgardsormr » Thu May 30, 2019 7:48 am

RBemendo wrote:
Thu May 30, 2019 6:02 am
Is there a way to Delete all nodes between LDR and SVR, then continue the script for auto applying?
This will delete everything aside from tools called LDR and SVR:

Code: Select all

comp:StartUndo('Very Bad Idea')
for i, tool in ipairs(comp:GetToolList(false)) do
    if tool.Name ~= "LDR" and tool.Name ~= "SVR" then
        tool:Delete()
    end
end
comp:EndUndo(true)
If you want to only delete tools that are connected between the two, leaving nodes that don't have connections alone, it's a little more involved. You'd need a recursive function similar to this:

Code: Select all

comp:StartUndo('Bad Idea')
function deleteDownstreamTools(tool)
    for i, outp in ipairs(tool:GetOutputList()) do
        for j, tool2 in ipairs(outp:GetConnectedInputs():GetTool()) do
            if tool2 then
                deleteDownstreamTools(tool2)
            end
            if tool2.Name ~= "SVR" and tool2.Name ~= "LDR" then
                tool2:Delete()
            end
        end
    end
end
comp:EndUndo(true)
I'm not 100% certain of that code, and recursion always makes my head hurt, so be careful with it.

You may want a double sanity check on the script, regardless of which approach you choose, to be sure someone doesn't delete their entire comp by running it accidentally.

User avatar
SirEdric
Fusionator
Posts: 1965
Joined: Tue Aug 05, 2014 10:04 am
Answers: 4
Real name: Eric Westphal
Been thanked: 136 times
Contact:

Re: Auto applying a template between loader and saver

#32

Post by SirEdric » Thu May 30, 2019 9:47 am

Wouldn't it be better to go with if tool:GetAttrs().TOOLS_RegID ~= 'Loader' ... rather than checking for the Name?

User avatar
Midgardsormr
Fusionator
Posts: 1216
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 3
Location: Los Angeles, CA, USA
Been thanked: 96 times
Contact:

Re: Auto applying a template between loader and saver

#33

Post by Midgardsormr » Thu May 30, 2019 10:45 am

Not necessarily; you might have Loaders in the comp that you don't want or need to preserve. Obviously it can be filtered in any fashion that meets the needs of the pipeline. For instance, I have a similar script that clears out nodes of specific types that are present in the 'wrong' template. I have a table of RegID strings and use bmd.isin(): if bmd.isin(nodeTypes, tool:GetAttrs().TOOLS_RegID) then …

edit: Now that you mention it, though, it would be a good idea to feed the end-point node as an argument to the function.

Code: Select all

function deleteDownstreamTools(tool, endTool)
    for i, outp in ipairs(tool:GetOutputList()) do
        for j, tool2 in ipairs(outp:GetConnectedInputs():GetTool()) do
            if tool2 then
                deleteDownstreamTools(tool2)
            end
            if tool2 ~= tool and tool2 ~= endTool then
                tool2:Delete()
            end
        end
    end
end
You'd need to find endTool in the comp, of course, and that would probably go back to retrieving it by its name, but the function is now more generalized.

User avatar
RBemendo
Fusioneer
Posts: 153
Joined: Fri Dec 12, 2014 11:32 am
Been thanked: 1 time

Re: Auto applying a template between loader and saver

#34

Post by RBemendo » Sat Jun 01, 2019 4:42 am

This is great guys, thank you so much.

User avatar
RBemendo
Fusioneer
Posts: 153
Joined: Fri Dec 12, 2014 11:32 am
Been thanked: 1 time

Re: Auto applying a template between loader and saver

#35

Post by RBemendo » Mon Jul 08, 2019 10:21 am

I'm digging back into this automation process of "repeatable" templates. I'm wondering if it's possible to apply the same template to multiple comp files as a batch?