Hello,
assuming that your script has successfully identified a source [path property] and a target [2D point property] (that actually carry keyframes, not their parents with customizable names etc), here are the rough steps. Actually the hardest part is not to read/write the source/target but to correctly handle already existing keyframes on the target (for instance if you apply the script for the second time on the same target) especially if you want to set the keyframes roving. The sketch below doesnt handle that.
*** slt means strictly less than ***
to read the path content, do:
var shape = source.value,
verts = shape.vertices,
inTan = shape.inTangents,
outTan = shape.outTangents,
numVerts = verts.length;
or use valueAtTime if you want to read the path at a specific time;
vertices is an array of 2D points, in and out tangents arrays of 2D vectors (which in pratice is the same).
If the path is closed and you want to have a motion that takes it into account, do:
if (shape.closed) {verts.push(verts[0]); inTan.push(inTan[0]); outTan.push(outTan[0]); numVerts++;};
Then you also must inject 2D tangents into 3D because tangents for a motion path are always 3D (even for 2D):
for (var k = 0; k slt numVerts; k++) inTan[k][2] = outTan[k][2] = 0;
Finally you have to specify a collection of numVerts times to write the keys. This is a matter of choice. You can choose a 2 seconds time interval from the current comp time (like AE does), or what ever you want.
Once you have chosen these times, assuming they are arranged into an array:
target.setValuesAtTimes(times, verts);
for (var idx, k=0; k slt numVerts; k++)
{
idx = target.nearestKeyIndex(times[k]);
target.setSpatialTangentsAtKey(idx, inTan[k], outTan[k]);
}
To set roving:
for (var idx, k=0; k slt numVerts-1; k++)
{
idx = target.nearestKeyIndex(times[k]);
target.setRovingAtKey(idx, true);
}
Xavier.