Wasn’t that easy after all,
But spent the whole week end trying to figure it out. if any one is interested
It works only for one property, if some one wants to enhance it to be able to select multiple properties you are welcome to do so.
below is the code.
Maybe someone can clean it up a little, this is the first time I write a script, and I’m pretty happy about the results.
Works like that:
Create your keyframes and add markers to what I call the origin layer.
Create a null and place the markers with there corresponding comment to where you need them.
Select the property from the origin layer and run the script
Enjoy.
var myComp = app.project.activeItem; // get the selected layer
var layerIdx = myComp.selectedLayers[0].index; // grab index of selected layer
var layer = myComp.layer(layerIdx); //set the selected layer
var propIdx = layer.selectedProperties.length - 1; //Get how many properties are selected if more than one only the last one is retained, had to do this as for path it always select the group and the path
var prop = layer.selectedProperties[propIdx]; // set variable to point to the last selected propertiies
var oNumMarkers, origList, nL, layerList, mLayer, dupLayer;
layerList = new Array();
origList = new Array();
dialog();
function dialog(){
// get how many layers there are in the composition
nL = myComp.numLayers;
// create a list of all the comp name for a drop down list
for (var q = 1; q<=nL; q++) {
layerList[layerList.length] = q + " - " + myComp.layer(q).name;
}
// create the popup window
var myWin = new Window("palette","Select marked layer", undefined);
var dd = myWin.add("dropdownlist",undefined,layerList) ;
dd.selection =layerIdx - 2; // set selection to a layer higher than selected layer (assuming this is where you will placed your marked layer)
var but = myWin.add("button",undefined,"Select Layer");
but.onClick = function () {
// This is where the fun starts
app.beginUndoGroup ("Match keys to markers");
mLayer = myComp.layer(dd.selection.index + 1); // set the layer continaing the final marker in position
oNumMarkers = layer.property("Marker").numKeys; // get the total number of markers availble in the original layer
// Create an array containing the value at each marker from the original layer
for (var i = 1; i <=oNumMarkers; i++) {
var name =layer.property("Marker").keyValue(i).comment;
var time = layer.property("Marker").keyTime(i);
var val = prop.valueAtTime(time,true);
origList[origList.length] = {'name': name, 'time': time, 'value': val}
}
// Duplicate the selected layer, rename the duplicated layer same as original layer. and rename original layer to append Results at the end
// Ended up to be easier to make a copy of the original layer, and then modify the original layer rather that modify the keys from the duplicated layer
dupLayer = layer.duplicate();
dupLayer.name = layer.name;
layer.name = layer.name + "_Results";
dupLayer.enabled = false; // Disable duplicated layer
// Remove all markers and keyframes from the original layer, safe now since we have duplicated it and have already store all the data it contains in origList array
for (var j = 1; j <=oNumMarkers; j ++){
layer.property("Marker").removeKey(1);
prop.removeKey(1);
}
//Place the correspondies keyframe to the corresponding markers by
// Getting the first marker comment and time
// then looping through origList to find the corresponding comment, and get its value
// finally place that value on in the corresponding properties
for (var k = 1; k <= mLayer.property("Marker").numKeys; k ++) {
rName = mLayer.property("Marker").keyValue(k).comment;
rTime = mLayer.property("Marker").keyTime(k);
for (var r = 0; r < oNumMarkers; r++){
if (rName == origList[r].name) {
rVal = origList[r].value;
}
}
prop.setValueAtTime(rTime,rVal);
var mv = new MarkerValue(rName);
layer.property("Marker").setValueAtTime(rTime,mv);
}
layer.moveBefore(mLayer); // move the result layer before the layer with the markers
app.endUndoGroup();
myWin.close();
}
myWin.center();
myWin.show();
}