ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Accessing marker.nearestKey from ExtendScript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Reuben Lara
Accessing marker.nearestKey from ExtendScript
on Oct 8, 2018 at 2:54:03 pm

Dan Ebberts: I'm using your marker code to implement a ScriptUI panel to manage some marker functionality. I'm trying to access nearest key from within a button function based on your code at motionscript.com. I've used it successfully inside property expressions, but can't get the nearestKey to work when called from a .jsx file.

Essentially just trying to retrieve the name of a marker if the current time is within the span of a split layer marker.

I can get to the alert("got here 1") and no further. No combination of the following seem to work for me:

n = mySelection[0].marker.nearestKey(time).index;
n = mySelection[0].markers.nearestKey(time).index;
n = markers.nearestKey(time).index;

What am I doing wrong? or maybe I'm way over complicating this? Thanks!

DAN'S CODE:
n = 0;
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (marker.key(n).time > time){
n--;
}
}

if (n == 0){
0
}else{
//...some code
}

MY CODE:
function getMarkerName(){

var mySelection = app.project.activeItem.selectedLayers;
var myComp = app.project.activeItem;

if (mySelection.length &lt; 1){

alert("select a layer");

}else{
//grab marker data
var layer = mySelection[0];
var markers = layer.property("Marker");

var n = 0;

if (markers.numKeys > 0){
alert("got here 1");
n = mySelection[0].marker.nearestKey(time).index;
alert("got here 2");
if (n > time){
alert("got here 3");
n--;
}
alert("got here 4");
}

if (n == 0){
alert("got here 5");
}else{
alert("got here 6");
var m = markers.key(n);
var markerName = m.comment;

if( (time > m.time) && (time &lt; (m.time-m.duration)) ){

return(markerName);

}else{
alert("no marker here");
}
}
}

}


Return to posts index

Dan Ebberts
Re: Accessing marker.nearestKey from ExtendScript
on Oct 8, 2018 at 3:12:42 pm

In general, scripting isn't going to understand expression syntax. Specifically, nearestKey(time) isn't going to work. Scripting does have nearestKeyIndex(), so you could do something like this:

var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
var myMarker = myLayer.property("Marker");
var myIndex = myMarker.nearestKeyIndex(myComp.time);
alert (myIndex);


Dan



Return to posts index

Reuben Lara
Re: Accessing marker.nearestKey from ExtendScript
on Oct 8, 2018 at 3:14:35 pm

No wonder i've been banging my head. Thanks!


Return to posts index

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