Skip to main content
bluebeezle
Inspiring
February 17, 2015
Question

Is there a way to call Collect Files with Extendscript?

  • February 17, 2015
  • 2 replies
  • 6193 views

I'd like to be able to create a script that collects files to a watch folder on the network and triggers our render machines that are watching said folder to start rendering, all with the click of a single button. Unfortunately, I haven't been able to find a way to call File>Dependencies>Collect Files with Extendscript. Is there away to do that? So far I've only found a script that manually copies all the files itself rather than using AE's Collect Files feature, but doing this fails to trigger the render from the computers watching the folder.

Thanks.

This topic has been closed for replies.

2 replies

Participant
May 8, 2017

I revisited this on a new project and decided to rewrite it basically from scratch. It's much cleaner/more robust now, and in every way I can think of mimics the features of the default Collect Files function (except one small limitation mentioned below).

You can get it here: Collect function for whoever wants it! - AE ENHANCERS

Enjoy!

- Spencer

Inspiring
April 6, 2023

Hi Spencer, this file no longer exists. Could you update it or send it to me by mail?

Regards

Inspiring
May 15, 2023

Not sure where their file went, but here is a function I rewrote for my own workflow. Hopefully this works for yours as well.

 

function collect_files(target_path){

    // extract project name, removing the .ae
    var project_name = app.project.file.name.slice(0,-4);

    var project_dir = new Folder(target_path.toString() + "/" + project_name + "_COLLECT");
    var footage_dir = new Folder(project_dir.absoluteURI + "\\(Footage)\\");


    for (i = 1; i <= app.project.numItems; i++){
        item = app.project.item(i)

        // Check these before continuing.
        if (item instanceof FootageItem == false){continue};
        if (item.file == null){continue};
        if (item.footageMissing){continue};

        // Get item's extension. Will be used to differentiate between image sequences and other media.
        var item_extension = item.file.name.substring(item.file.name.lastIndexOf(".") + 1).toLowerCase();
     
        // Make the item's directory if it doesn't exist
        var item_dir = new Folder(footage_dir.absoluteURI + "\\" + item.parentFolder.name);
        if (!item_dir.exists){item_dir.create()};

        // Create target dir and target file variables
        var target_dir = new Folder(footage_dir.absoluteURI + "\\" + item.parentFolder.name);
        var target_file = new File(target_dir.absoluteURI + "\\" + item.file.name);

        // Break if target file already exists
        if (target_file.exists){continue}

        // If the target is a still.
        if (item.mainSource.isStill){
            item.file.copy(target_dir.absoluteURI + "\\" + item.file.name);
            item.replace(target_file);
            continue
        }

        // list of still image extensions
        var still_extensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico', 'tif', 'tiff', 'eps', 'raw', 'ai', 'ps', 'indd', 'pdf', 'xcf', 'sketch', 'xd', 'cin', 'dpx','exr','pxr','rla','hdr','tga'];
        
        // If it's a video file (doesn't contain an image extension)
        if (still_extensions.indexOf(item_extension) == -1){
            item.file.copy(target_dir.absoluteURI + "\\" + item.file.name);
            item.replace(target_file);
            continue
        }

        // If it's a image sequence.
        if (still_extensions.indexOf(item_extension) != -1){
            var source_folder = item.file.parent;
            var frames = source_folder.getFiles();

            for (f = 0; f<frames.length; f++){
                frame = frames[f]
                frame.copy(target_dir.toString() + "\\" + frame.name)
            }

            try {
                item.replaceWithSequence(target_file, true)
            } catch (e){
                alert(item.name)
            }

 
        }
    }

    app.project.save(new File(project_dir.absoluteURI + "\\" + app.project.file.name));
}

Thanks for taking the time to share this code.

Alex White
Legend
February 17, 2015

To call to call File>Dependencies>Collect Files try this one:

app.executeCommand(2482);

bluebeezle
Inspiring
February 18, 2015
  1. Thanks! I should've mentioned I actually had tried that one but the problem is it still requires the user to browse to a directory and confirm. I'd like to be able to collect to a predefined directory without further input from the user.
Alex White
Legend
February 18, 2015

I`m afraid there is no way to avoid that user dialog.

AFAIK the only way to do that is to write collect function from scratch.