Recursive duplication of a comp into an independent one

Hi Alon,
hope you are doing fine!
I would like to duplicate a comp with all its subcomps so that I have an independent ‘standalone’ comp, saved in a new project folder along with the duplicated subcomps. The ‘common’ layers can stay the same bc I need to exchange them manually anyways.
There are some ideas but I wanted to ask you for advice as a guideline how you would start this. I can duplicate, rename, create folders, move inside the project etc. but then I’m stuck…

First thought was what if I duplicated the layers in the original comp, then precomp. Alpha and parent links move along with that fine. But I don’t know where to put the loop to do this recursively for sub-comps. ‘Starting from bottom up’ so to speak.
Not sure if I’m over or underthinking :wink:

Of course there is a paid script for that - I’m basically trying to do the same thing - looks pretty sophisticated, $25 is okay and in case it’s too complicated I would go for that but tbh I just wanted to see if I could do it in Automation Toolkit :slight_smile:

https://aescripts.com/true-comp-duplicator/

Thx in advance!
Peter

Hi @thepetercoin , I am fine thank you!

The True Comp Duplicator script, is priced at “Name Your Own Price” so you can essentially get it for free if you type 0 as the price, so it will probably will make more sense to get this tool as it is the best solution for this job.
I assume it will handle edge cases a lot better than a newly written script.



If you still want to do it with automation toolkit I think it can be done, but some features will be quite hard to implement (like expression fixing).

lets start by analyzing the regular duplication process -
When you duplicate a comp, the only connections to the original source are the common precomps that are now in both of the source and the duplicated version. solids, adjustments, null objects, shapes, cameras and other types of layers would behave differently in the new duplicated comp so they do not need a special attention.

the in order to make the precomps unique too, we will need to duplicate their source and replace their layers with the new duplicated one.

so the process involves duplicating the main comp, creating a list of all the decedents precomps of the main comp, duplicating all of them, moving them to a new folder, replace each precomp layer in the new duplicated main comp with the new precomps.

I am working to create an example of this automation but it will take some time as it is not a straightforward process.

i will get back to you soon :+1:

Hey Alon,
fast as always! Thx for your suggestions. If you say some features would be hard to implement I absolutely believe you. So for now I will get the other script - pls don’t worry about creating an example. It would be interesting but let’s not steal your time for this! :slight_smile:

Hi @thepetercoin ,
This is a cool challenge for me too, so I’m glad to help you out with it.
It took a bit of brainstorming to figure out an algorithm that nails this.

I had to crack this too because Automation Toolkit doesn’t support recursion by design—it’s a bit too easy to run into infinite loops, and recursion can get pretty complex for most users. So, I figured it’s better for the overall user experience to keep it simple.

But then I remembered the pre-made recursion in the loop feature, which fits perfectly for this job.

When the “precomps” checkbox on the right side is checked, this loop will run on the specified composition and all its descendant precomps too.

In this example automation I colored each part in different color,
Here is a summery of what each part does:

  1. Purple: Create a variable for the active composition, duplicate it, and save the duplicated main comp as a variable too.
  2. Blue: Create a collection that stores all the original precomps from the active comp. This uses the precomps checkbox to find all of them recursively, adding any precomps that aren’t already in the collection, ensuring each precomp is only added once.
  3. Yellow: Add a folder to the project panel, set its name, and save it as a variable.
  4. Red: Create a collection for the duplicated precomps. Loop over the original precomps collection, move each precomp to the folder in the project panel, duplicate it in the folder, add the duplicated version to the duplicated precomps collection, and finally move it back to its previous location in the project panel hierarchy. This way, we’ve created a duplicate for each precomp used in the active comp, placed them all in a specific folder, and added them to a specific collection. Both collections are created in the same order, so if we need to replace a layer from collection 1, we replace it with the corresponding precomp from collection 2 at the same index.
  5. Green: Loop over the layers in the duplicated active comp and replace each precomp with its matching duplicate from the duplicated precomps collection. We loop over all the layers, and if we find a precomp layer, we loop over the original precomp collection to find the matching precomp. When we find it, we take the precomp from the duplicated collection at the same index and replace the layer with this element.
  6. Purple (again): Do the same as the green part but for all the duplicated precomps. Loop through all precomps in the duplicated precomps collection and replace their precomp layers with matching duplicates.
  7. Blue (again): Open the new duplicated active comp in the view.

download-
Deep Comp Duplicator.zip (7.3 KB)

This is the most basic comp duplicator with deep duplications. We could add features like suffix and prefix options for duplicated precomp names, options to not group them into one folder, options to exclude files with specific prefixes, deep limit (not sure if possible), updating expressions (maybe possible but needs more thought), duplicating footage, and making multiple copies.

Adding all these features would take more work and make it more complicated, so let’s keep it simple for now and expand as needed.

There might be some bugs, and I’m not 100% sure it works perfectly yet, so more testing is definitely needed.

Whoa. Just tried it. Haven’t noticed any bugs yet. As you say, basics, but exactly what I imagined and does what it should. So cool that it works in Automation Toolkit, thank you very much! Also I love it when you add so many comments :slight_smile: