12 Replies Latest reply on May 7, 2017 5:47 PM by Spencer_t

    Is there a way to call Collect Files with Extendscript?

    bluebeezle Level 1

      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.

        • 1. Re: Is there a way to call Collect Files with Extendscript?
          Alex+White Level 3

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

           

          app.executeCommand(2482);
          
          • 2. Re: Is there a way to call Collect Files with Extendscript?
            bluebeezle Level 1
            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.
            • 3. Re: Is there a way to call Collect Files with Extendscript?
              Alex+White Level 3

              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.

              • 4. Re: Is there a way to call Collect Files with Extendscript?
                bluebeezle Level 1

                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?

                • 5. Re: Is there a way to call Collect Files with Extendscript?
                  Alex+White Level 3

                  Sure, just add

                   

                  app.project.renderQueue.item(index).render
                  

                   

                  or

                   

                  app.project.renderQueue.render();
                  

                   

                  after your project will be ready.

                  • 6. Re: Is there a way to call Collect Files with Extendscript?
                    bluebeezle Level 1

                    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.

                    • 7. Re: Is there a way to call Collect Files with Extendscript?
                      Alex+White Level 3

                      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=""

                      • 8. Re: Is there a way to call Collect Files with Extendscript?
                        bluebeezle Level 1

                        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!

                        • 9. Re: Is there a way to call Collect Files with Extendscript?
                          chriss31919561 Level 1

                          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

                          • 10. Re: Is there a way to call Collect Files with Extendscript?
                            bluebeezle Level 1

                            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[j].copy(dossierSequenceTarget.absoluteURI + "\\" + frameSequence[j].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;

                                }

                             

                             

                            • 11. Re: Is there a way to call Collect Files with Extendscript?
                              Spencer_t Level 1

                              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[j] instanceof File) {

                                                          frameSequence[j].copy(dossierSequenceTarget.absoluteURI + "\\" + frameSequence[j].name);

                                                         

                                                        }

                                                      }

                               

                               

                                                      //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;

                              }

                              • 12. Re: Is there a way to call Collect Files with Extendscript?
                                Spencer_t Level 1

                                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