setting a layer active (with the currentLayer property) isn't the same a selecting it (with setSelectedLayers method). ie, use:
tl.setSelectedLayers(i)
Thanks kglad, that was it. So now, how to copy frames from a library item and paste into the same named layers in the current timeline:
// Define this timeline
var dom = fl.getDocumentDOM();
var tl = dom.getTimeline();
var layers = tl.layers;
// Define the library item
var pName = String(tl.name + '/puppet/' + tl.name + '_poses')
dom.library.selectItem(pName)
var copyTL = dom.library.getSelectedItems()[0].timeline;
var copyTLArray = copyTL[1];
// Copy and paste frames variables
var cFrom = 1
var cTo = 2
var pFrom = tl.currentFrame
var pTo = pFrom + (cTo - cFrom)
// Iterate Over copyTLArray and copy frames to paste into tl
for (i = 0; i < copyTLArray.length; i++) {
// Copy frames from copyTL
copyTL.setSelectedLayers(i)
copyTL.currentLayer = i
copyTL.setSelectedFrames(cFrom, cTo);
copyTL.copyFrames(cFrom, cTo+1);
// Select layer in tl based on name of copyTL[i].name
var index = Number(tl.findLayerIndex(copyTLArray[i].name))
if (!index) {
fl.trace("No layer called + " + copyTLArray[i].name)
}
else {
// Check if keyframe exists
var cLayer = layers[index]
var frame = cLayer.frames[tl.currentFrame];
var keyframe = frame.startFrame == tl.currentFrame
// Select layer and frames
fl.trace("huh = " + copyTLArray[i].name + " " + index)
tl.setSelectedLayers(index)
tl.setSelectedFrames(pFrom, pTo);
if(!keyframe){ // if false
var tFrame = tl.currentFrame;
tl.convertToKeyframes(tFrame);
}
tl.pasteFrames(pFrom, pTo+1);
}
}
This code also adds a keyframe in the current tl.layer if there isn't one, but so far only returns a trace output if there is a layer in the symbol item that isn't already in the tl.