Skip to main content
Known Participant
January 26, 2021
Answered

ExtendScript: Apply template not working?

  • January 26, 2021
  • 2 replies
  • 1987 views

I am quite new to AE scripting though I have made a lot of ExtendScripts for Photoshop and Indesign. Now, I am trying to set up a workflow where I add a comp to the render queue and render it. As far as I understand, the only way to specify a Codec is by specifying a template. However, I only get an error that it's "not a valid template name". Just as a way to duoble check and eliminate any typos, I used the list of template names as an input but still get that very same error. Do anyone know if there is a way around this?

My example:

// add to render queue:
project.renderQueue.items.add(comp);
// getting an actual template name:
var template = project.renderQueue.item(1).outputModule(1).templates[10];
// trying to set the template
project.renderQueue.items.add(comp).applyTemplate(template);

 

This topic has been closed for replies.
Correct answer Paul Tuersley

That last line looks wrong, trying to set the template at the same time you're adding the comp to the RQ. You seem to be confusing the two different uses of ApplyTemplate, one used directly on the RQItem object to set the render settings and one used on any OutputModule object to set the OM template.

 

Haven't tested this but try replacing the last line with:

alert(template); // just to make sure what you grabbed appears to be right
var theRender = project.renderQueue.items.add(comp);
theRender.outputModule(1).applyTemplate(template);

 

 

 

 

2 replies

Paul TuersleyCorrect answer
Inspiring
January 26, 2021

That last line looks wrong, trying to set the template at the same time you're adding the comp to the RQ. You seem to be confusing the two different uses of ApplyTemplate, one used directly on the RQItem object to set the render settings and one used on any OutputModule object to set the OM template.

 

Haven't tested this but try replacing the last line with:

alert(template); // just to make sure what you grabbed appears to be right
var theRender = project.renderQueue.items.add(comp);
theRender.outputModule(1).applyTemplate(template);

 

 

 

 

Known Participant
January 26, 2021

Yes, you are right thera are an error in that example. I have to add it before I get the template names though, since it won't be present otherwise. I will do some more testing.

Known Participant
January 26, 2021

That actually was it, it worked when I changed to:

var theRender = project.renderQueue.items.add(comp);//.applyTemplate(template);
var template = project.renderQueue.item(1).outputModule(1).templates[10];
theRender.outputModule(1).applyTemplate(template);

 

Thank you for the help! I believe the error message was the confusing part.

Mylenium
Legend
January 26, 2021

Start by actually not naming your variable "template". It's always bad practice to use words plainly that may be reserved keywords and could confuse the parser.

 

Mylenium

Known Participant
January 26, 2021

Well thank you but I would appreciate if you actually tried to help me with the issue instead of nitpicking. The above is just an example and not code I intend to use. I get the same error when I use a string with the actual template name.

Known Participant
May 23, 2023

Really?  This was good advice, and snapping back at community members really is unlikeley to get you any meaningful discussion.  It doesn't take much to be nice.  I hope you sorted your issue.  It looks like Pauls answer is a good one.  I'm about to try it myself.