Highlighted

How do I specify a render location using scripting? i.e. how do I hard-code the "Output to:" folder?

Participant ,
Nov 11, 2020

Copy link to clipboard

Copied

For certain jobs I have specific render requirements, so I made a Script UI button that queues the selected comp and applies render settings and output modules…

 

var myItems = app.project.selection;
var comp, item, outputModule;

for (var i = 0; i < myItems.length; i ++){
  if (! (myItems[i] instanceof CompItem)) continue;
  comp = myItems[i];
  
item = app.project.renderQueue.items.add(comp);
outputModule = item.outputModule(1);
outputModule.applyTemplate("Apple ProRes 422 HQ 16 Bit");
item.applyTemplate("Best Settings - 16 Bit");
}

 

It works great. However, I want to add a custom render destination that renders into a folder, and the folder name needs to be the name of the AE project. I don't want to change my default render location, so I need to change the output in this script instead.

 

I'm on a Mac and the location I need is /Volumes/Renders/[name of project]/

 

Is this possible? And if so, how would I do modify my code to do that?

Try this:

var myItems = app.project.selection;
var comp, item, outputModule, myFile, myFolder;

// make sure project has been saved
if (app.project.file == null) alert("save your project first!");
else {
  for (var i = 0; i < myItems.length; i++){
    if (myItems[i] instanceof CompItem) {
      comp = myItems[i];
    
      item = app.project.renderQueue.items.add(comp);
      outputModule = item.outputModule(1);
      outputModule.applyTemplate("Apple ProRes 422 HQ 16 Bit");
      item.applyTemplate("Best Settings - 16 Bit");

      // create folder object from path, including project name stripped of extension
      myFolder = new Folder("/Volumes/Renders/" + app.project.file.name.substring(0, app.project.file.name.lastIndexOf(".")));
      // check folder exists
      if (!myFolder.exists) {
        // create it if it doesn't
        if (!myFolder.create()) {
          // if create() returns false is couldn't be created for some reason so break out of the for loop and end
          alert("unable to create folder");
          break;
        }
      }
      //folder should now exist so create a file object using the folder path + the existing output module filename, then set the output module file
      if (myFolder.exists) {
        myFile = new File(myFolder.fsName + "/"+outputModule.file.name);  
        outputModule.file = myFile;
      }
    }
  }
}
TOPICS
Scripting

Views

39

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I specify a render location using scripting? i.e. how do I hard-code the "Output to:" folder?

Participant ,
Nov 11, 2020

Copy link to clipboard

Copied

For certain jobs I have specific render requirements, so I made a Script UI button that queues the selected comp and applies render settings and output modules…

 

var myItems = app.project.selection;
var comp, item, outputModule;

for (var i = 0; i < myItems.length; i ++){
  if (! (myItems[i] instanceof CompItem)) continue;
  comp = myItems[i];
  
item = app.project.renderQueue.items.add(comp);
outputModule = item.outputModule(1);
outputModule.applyTemplate("Apple ProRes 422 HQ 16 Bit");
item.applyTemplate("Best Settings - 16 Bit");
}

 

It works great. However, I want to add a custom render destination that renders into a folder, and the folder name needs to be the name of the AE project. I don't want to change my default render location, so I need to change the output in this script instead.

 

I'm on a Mac and the location I need is /Volumes/Renders/[name of project]/

 

Is this possible? And if so, how would I do modify my code to do that?

Try this:

var myItems = app.project.selection;
var comp, item, outputModule, myFile, myFolder;

// make sure project has been saved
if (app.project.file == null) alert("save your project first!");
else {
  for (var i = 0; i < myItems.length; i++){
    if (myItems[i] instanceof CompItem) {
      comp = myItems[i];
    
      item = app.project.renderQueue.items.add(comp);
      outputModule = item.outputModule(1);
      outputModule.applyTemplate("Apple ProRes 422 HQ 16 Bit");
      item.applyTemplate("Best Settings - 16 Bit");

      // create folder object from path, including project name stripped of extension
      myFolder = new Folder("/Volumes/Renders/" + app.project.file.name.substring(0, app.project.file.name.lastIndexOf(".")));
      // check folder exists
      if (!myFolder.exists) {
        // create it if it doesn't
        if (!myFolder.create()) {
          // if create() returns false is couldn't be created for some reason so break out of the for loop and end
          alert("unable to create folder");
          break;
        }
      }
      //folder should now exist so create a file object using the folder path + the existing output module filename, then set the output module file
      if (myFolder.exists) {
        myFile = new File(myFolder.fsName + "/"+outputModule.file.name);  
        outputModule.file = myFile;
      }
    }
  }
}
TOPICS
Scripting

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 11, 2020 0
Engaged ,
Nov 11, 2020

Copy link to clipboard

Copied

Try this:

var myItems = app.project.selection;
var comp, item, outputModule, myFile, myFolder;

// make sure project has been saved
if (app.project.file == null) alert("save your project first!");
else {
  for (var i = 0; i < myItems.length; i++){
    if (myItems[i] instanceof CompItem) {
      comp = myItems[i];
    
      item = app.project.renderQueue.items.add(comp);
      outputModule = item.outputModule(1);
      outputModule.applyTemplate("Apple ProRes 422 HQ 16 Bit");
      item.applyTemplate("Best Settings - 16 Bit");

      // create folder object from path, including project name stripped of extension
      myFolder = new Folder("/Volumes/Renders/" + app.project.file.name.substring(0, app.project.file.name.lastIndexOf(".")));
      // check folder exists
      if (!myFolder.exists) {
        // create it if it doesn't
        if (!myFolder.create()) {
          // if create() returns false is couldn't be created for some reason so break out of the for loop and end
          alert("unable to create folder");
          break;
        }
      }
      //folder should now exist so create a file object using the folder path + the existing output module filename, then set the output module file
      if (myFolder.exists) {
        myFile = new File(myFolder.fsName + "/"+outputModule.file.name);  
        outputModule.file = myFile;
      }
    }
  }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0
Participant ,
Nov 11, 2020

Copy link to clipboard

Copied

That works great!! Thanks again Paul! And also I appreciate the thoughtful additions you made such as making sure the project has initially been saved, and checking if the folder exists.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0
Engaged ,
Nov 11, 2020

Copy link to clipboard

Copied

No problem. Those things were for my benefit too. First error I got when testing it was 'null is not an object' because I was using an unsaved test project!

 

To add to your list of required reading, here's the Adobe Javascript Tools guide which contains things like file system access, script UI and other things specific to Extendscript across Adobe apps but not specfic to After Effects. This is what I dipped into for a quick refresher when writing the code.

https://www.adobe.com/content/dam/acom/en/devnet/scripting/estk/javascript_tools_guide.pdf

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 1
Participant ,
Nov 11, 2020

Copy link to clipboard

Copied

Thanks! That's really helpful.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0