ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using the timeToTimecode function in a script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
James Malcolm
Using the timeToTimecode function in a script
on Sep 2, 2019 at 6:24:02 pm

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&lt;=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;
// &lt;>
// >>>
preComp.name = compName;
// &lt;&lt;&lt;
// &lt;&lt;&lt;
}

app.endUndoGroup();
}

precompTrim();
}


Return to posts index

Dan Ebberts
Re: Using the timeToTimecode function in a script
on Sep 2, 2019 at 7:49:56 pm

Scripting doesn't have the timeToTimecode() function, but you could add a temporary text layer to the comp, add the expression to the text layer, harvest the result, and delete the text layer.'


Dan



Return to posts index

James Malcolm
Re: Using the timeToTimecode function in a script
on Sep 2, 2019 at 10:25:02 pm

Ah ok. Thanks for the workaround suggestion though, Dan!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]