Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
To call to call File>Dependencies>Collect Files try this one:
app.executeCommand(2482);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I actually found a collect script written from scratch that I can use. It'll copy all dependent files to the directory. It doesn't trigger the render machines watching that directory to start rendering though. Do you know if there's a way to force it to trigger the render from any machines watching that output directory?
Copy link to clipboard
Copied
Sure, just add
app.project.renderQueue.item(
index
).render
or
app.project.renderQueue.render();
after your project will be ready.
Copy link to clipboard
Copied
nah, that starts the render on the machine I'm collecting from. I'm trying to collect files from my current machine to the network, and have render machines (NOT the computer I'm collecting from) that are watching that output directory start rendering. They'll do that if I use AE's built in Collect Files feature, but not if I manually collect the files to the output directory.
Copy link to clipboard
Copied
1. Setup watch folder on your render machines.
2. Collect files with enabled option ("Enable Watch Folder render").
3. Copy all collected files and folders to Watch Folder.
4. Render will automatically start on all machines.
So if the script you found haven`t "Enable Watch Folder render", it can be implemented to it.
AFAIK this option creates new text file like projectname_RCF.text
and consists something like this:
After Effects 12.2v1 Render Control File
max_machines=5
num_machines=0
init=0
html_init=0
html_name=""
Copy link to clipboard
Copied
ah yeah, I had seen those files but I wasn't sure if that was created by the render, or if the creation of the text file in a watched directory is what triggered the render. I suspected it might (unfortunately) be the former since the file is updated as it renders (num_machines is the number of machines currently participating in the render). I'll see if I can recreate the RCF text file when I manually collect, and hopefully it'll trigger the render. Might not get to it until next week, though.
Thanks, for now!
Copy link to clipboard
Copied
Hi BlueBeezle,
Could you share the code that does the "Collect Files" action?
I've written my own code and it's correctly copying the files to a location.
However, some FootageItems come from the same Illustrator file (for example bookstore.ai),
but are referring to different layers of that file.
When writing my function (to simulate "Collect Files"), do you know how to tell AfterEffects
to use a specific layer for that item?
Thanks,
Chris
Copy link to clipboard
Copied
Sorry, just saw this!
I'm not quite following what you're asking, but I'd be happy to share the code - I found it online, so pardon the French
function collect($dir) { //dossierRassembler, c'est le dossier de destination, plan, c'est une chaine de caractère : le nom du projet/numéro du plan, ou n'importe quoi d'autre défini par l'utilisateur
//créer le dossier du plan
var projectDir = new Folder($dir);
var footageDir = new Folder(projectDir.absoluteURI + "\\(Footage)\\");
projectDir.create();
footageDir.create();
//pour chaque item, si c'est un footage Item, le copier au nouvel emplacement dans le bon sous dossier puis le relinker
var item;
var targetFile;
for (i = 1; i <= app.project.numItems; i++)
{
var item = app.project.item(i);
if (item instanceof FootageItem)
{
//créer le dossier
var targetDir = new Folder(footageDir.absoluteURI + "\\" + item.parentFolder.name + "\\");
if (!targetDir.exists)
targetDir.create();
if (item.file != null && !item.footageMissing)
{
var extension = item.file.name.substring(item.file.name.lastIndexOf(".")+1).toLowerCase();
if (item.mainSource.isStill) // si c'est fixe
{
targetFile = new File(targetDir.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//déplacer
item.file.copy(targetDir.absoluteURI + "\\" + item.file.name);
//relink
item.replace(targetFile);
}
}
else if (extension != "jpg" && extension != "jpeg" && extension != "png" && extension != "tga" && extension != "tif" && extension != "tiff" && extension != "exr" && extension != "bmp" && extension != "pxr" && extension != "pct" && extension != "hdr" && extension != "rla" && extension != "ai" && extension != "cin" && extension != "dpx") {// si c'est pas un format d'image fixe
targetFile = new File(targetDir.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//déplacer
item.file.copy(targetDir.absoluteURI + "\\" + item.file.name);
//relink
item.replace(targetFile);
}
}
else
{ // reste les séquences d'images
//copie et remplacement en cas de séquence de fichier
//récupérer la liste des images et créer le nouveau dossier de destination
var dossierSequence = item.file.parent;
var frameSequence = dossierSequence.getFiles();
var dossierSequenceTarget = new Folder(targetDir.absoluteURI + "\\" + dossierSequence.name + "\\");
dossierSequenceTarget.create();
targetFile = new File(dossierSequenceTarget.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//copier les frames
for (j=0;j<frameSequence.length;j++)
{
frameSequence
.copy(dossierSequenceTarget.absoluteURI + "\\" + frameSequence .name); }
//relink
item.replaceWithSequence(targetFile, true);
}
delete dossierSequence;
delete frameSequence;
delete dossierSequenceTarget;
}
delete extension;
}
delete targetDir;
}
}
//sauvegarder le projet
app.project.save(new File(projectDir.absoluteURI + "\\" + app.project.file.name));
//virer les variables
delete projectDir;
delete footageDir;
}
Copy link to clipboard
Copied
Thanks, needed this myself! I tweaked the code a bit though because this threw an error if you had an image sequence with sub-folders within the parent directory (if that makes sense). It also didn't remember alpha interpretation settings, so I added that too. Here's my version if anyone wants it (I also translated the french):
//Folder Gather, this is the destination folder, map, it's a character string: the name of the project / plan number, or anything else defined by the user
function collect(collectDir) { //dossierRassembler, c'est le dossier de destination, plan, c'est une chaine de caractère : le nom du projet/numéro du plan, ou n'importe quoi d'autre défini par l'utilisateur
//créer le dossier du plan
//// create the plan folder
projectName = app.project.file.name.slice(0,-4);
var projectDir = new Folder(collectDir.toString() + "/" + projectName + "_COLLECT");
var footageDir = new Folder(projectDir.absoluteURI + "\\(Footage)\\");
projectDir.create();
footageDir.create();
//pour chaque item, si c'est un footage Item, le copier au nouvel emplacement dans le bon sous dossier puis le relinker
// for each item, if it's a footage item, copy it to the new location in the correct subfolder and then relinker
var item;
var targetFile;
for (i = 1; i <= app.project.numItems; i++)
{
var item = app.project.item(i);
if (item instanceof FootageItem)
{
//créer le dossier
// create the folder
var targetDir = new Folder(footageDir.absoluteURI + "\\" + item.parentFolder.name + "\\");
if (!targetDir.exists)
targetDir.create();
if (item.file != null && !item.footageMissing)
{
var extension = item.file.name.substring(item.file.name.lastIndexOf(".")+1).toLowerCase();
if (item.mainSource.isStill) // si c'est fixe
{
targetFile = new File(targetDir.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//move
item.file.copy(targetDir.absoluteURI + "\\" + item.file.name);
//relink
item.replace(targetFile);
}
}
else if (extension != "jpg" && extension != "jpeg" && extension != "png" && extension != "tga" && extension != "tif" && extension != "tiff" && extension != "exr" && extension != "bmp" && extension != "pxr" && extension != "pct" && extension != "hdr" && extension != "rla" && extension != "ai" && extension != "cin" && extension != "dpx") {// si c'est pas un format d'image fixe
targetFile = new File(targetDir.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//move
item.file.copy(targetDir.absoluteURI + "\\" + item.file.name);
//relink
item.replace(targetFile);
}
}
else
{ // reste les séquences d'images Remains the sequences of images
//copie et remplacement en cas de séquence de fichier Copy and replace in the case of a file sequence
//récupérer la liste des images et créer le nouveau dossier de destination Retrieve the list of images and create the new destination folder
var dossierSequence = item.file.parent;
var frameSequence = dossierSequence.getFiles();
var dossierSequenceTarget = new Folder(targetDir.absoluteURI + "\\" + dossierSequence.name + "\\");
dossierSequenceTarget.create();
targetFile = new File(dossierSequenceTarget.absoluteURI + "\\" + item.file.name);
if (!targetFile.exists)
{
//copier les frames
for (j=0; j<frameSequence.length; j++)
{
if (frameSequence
frameSequence
}
}
//relink
// This is a bit scary so if anything crashes, look here first!
app.executeCommand(2004); // desect all
item.selected = true;
app.executeCommand(2254); // remember interpretation
item.replaceWithSequence(targetFile, true);
item.selected = true;
app.executeCommand(2255); // apply interpretation
}
delete dossierSequence;
delete frameSequence;
delete dossierSequenceTarget;
}
delete extension;
}
delete targetDir;
}
}
//sauvegarder le projet
app.project.save(new File(projectDir.absoluteURI + "\\" + app.project.file.name));
//virer les variables
delete projectDir;
delete footageDir;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi Spencer, this file no longer exists. Could you update it or send it to me by mail?
Regards
Copy link to clipboard
Copied
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));
}
Copy link to clipboard
Copied
Thanks for taking the time to share this code.