-
Using the timeToTimecode function in a script
I’m trying to adapt VideoCopilot’s free ‘Trim Compose’ script, which precomposes multiple layers into trimmed comps.
Their original version appends the layer’s in and out points in frames to the precomp title, and I’d like to append the layer’s in point in 25fps timecode instead.
So I’m using the timeToTimecode expression, but I’m getting the error ‘Function timeToTimecode is undefined’ when I run the script.
The problem line in the below code is:
var layerTimecode = timeToTimecode(t=inPoint, timecodeBase=25, isDuration=false)I’ve tested this exact code in an expression within After Effects and it works just fine, but it doesn’t work when written into the script.
I also tried the code with ‘thisLayer.timeToTimecode’, but this doesn’t work, I think because the line is nested in a for loop?
Any suggestions on how to adapt the code and get it working?
{
function precompTrim()
{var curComp = app.project.activeItem;
if (!(curComp instanceof CompItem))
{
alert("Please select a composition.");
return;
}var layers = curComp.selectedLayers;
if (layers.length == 0)
{
alert("Please select one or more layers.");
return;
}app.beginUndoGroup("Precomp and Trim Layers");
var compFolder = prompt("Comp Folder Name", "Trimmed Comps");
var projItems = app.project.items;
for (var i=1; i<=projItems.length; i++)
if (projItems[i].typeName == "Folder" && projItems[i].name == compFolder)
{
compFolder = projItems[i];
break;
}compFolder = app.project.items.addFolder(compFolder);
var offset = parseInt(prompt("Add Handles (frames)", "0"));
offset = offset * curComp.frameDuration;for (var i=0; i>>
// >>>
var compName = layers[i].name;
var layerTimecode = timeToTimecode(t=inPoint, timecodeBase=25, isDuration=false)
var preCompName = compName + " " + layerTimecode;
// <>
// >>>
preComp.name = compName;
// <<<
// <<<
}app.endUndoGroup();
}precompTrim();
}