Control composition length
-
Hey,
I am searching for a solution to control the composition length from the json file.
Is there a way to achieve this using also templater?
Did anybody try this? -
Thanks for getting in touch with us. To change the composition length, you’ll probably need to use an advanced feature of Templater called Event Scripts. Event Scripts allow you to create custom actions at various points throughout the Templater process and can be very useful for this sort of situation. In this case, a script like this:
var myTime = $D.job.get("time"); var myTarget = $D.job.get("compname"); var myComp; for (var i = 1; i <= app.project.numItems; i ++) { if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === myTarget)) { myComp = app.project.item(i); break; } } myComp.duration = (myTime);
Will alter the duration of the comp based on variables in the data source. You’ll want to swap out “time” for the name of the layer with the duration (in seconds) and “compname” for the name of the comp you want to alter.
I’d recommended running this script on the “Before layers update” event so that the custom timing is applied before Templater processes the data into the layers. One final note, it should be possible to swap out
myComp.duration
formyComp.frameDuration
if you’d like to specify the length in frames rather than seconds. Hopefully, that’s enough to get started, but if you have any other questions, please feel free to let us know. Thanks! -
@jeff Thanks a lot, it’s exactly the answer I was looking for
-
@jeff I have one more additional question
I am trying to change also the starting point of a composition
but either of startTime or inPoint does not seem to work
Any idea why? -
After a cursory search, I think that both
startTime
andinPoint
only refer to layer properties instead of comp properties. Can you give us some more information about what you’re trying to achieve? It might be possible using Templater’s Time Sculpting properties or some other method. Thanks! -
@jeff it works like this:
var proj = app.project;
var vidComp = proj.item(1);
vidComp.layer(1).startTime = 3;I just can’t figure out how to change this to be able to take the information from the JSON.
also, I want to target predefined layer names like you did on the example you sent, not layer by layer index(var myTarget = $D.job.get(“compname”);) -
OK. I think this will work for what you’re trying to do:
var compName = $D.job.get("compname"); var layerName = $D.job.get("layername"); var layerTime = $D.job.get("time"); var myComp; for (var i = 1; i <= app.project.numItems; i ++) { if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === compName)) { myComp = app.project.item(i); break; } } myComp.layer(layerName).startTime = layerTime;
I’ll explain the methodology briefly here so that you can adjust as needed. The comp name is set by the “compname” field in the data source (more on that in a second), the layer by “layername”, the time value by “time”. These values can obviously be altered to fit your project as needed.
The code that begins with
var myComp;
is essentially a quick loop that searches your Project for the text outlined in thecompName
variable and returns the index value. That way, you can pick the comp using plain text rather than an index. The layer name within the comp can be designated by text, so that’s what thelayerName
variable is for.I tested this on the “Before layers update” event, and it seemed to work without an issue. It’s possible there might be some issues if you have a huge number of layers that all need updating, but this should be a good starting point. If you run into trouble, feel free to let us know, and we’ll see what we can do. Thanks!