-
Accessing marker.nearestKey from ExtendScript
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 < 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 < (m.time-m.duration)) ){
return(markerName);
}else{
alert("no marker here");
}
}
}}