I have an expression I use often which I want to make a one-click script.

It requires an expression on the position parameter and one on the rotation parameter.

I started off by trying to not use expressions, I don't want to have expression but rather, set values. I managed to do this with the position part of the expression

Code: Select all

```
a = thisComp.layer(thisLayer, -1).position;
b = thisComp.layer(thisLayer, -2).position;
c = thisComp.layer(thisLayer, -3).position;
(a+b+c)/3
```

Code: Select all

```
var aP = selectedLayers[0].property("position").value;
var bP = selectedLayers[1].property("position").value;
var cP = selectedLayers[2].property("position").value;
var posValue = (aP+bP+cP)/3;
```

Code: Select all

```
//~ n = cross((a-b),(a-c));
//~ orientation+lookAt(a, n)
```

Code: Select all

```
var aX = aP[0];
var aY = aP[1];
var aZ = aP[2];
var bX= bP[0];
var bY= bP[1];
var bZ= bP[2];
var cX= cP[0];
var cY= cP[1];
var cZ= cP[2];
var aVec = Vector.create([aX,aY,aZ]);
var bVec = Vector.create([bX,bY,bZ]);
var cVec = Vector.create([aX,bY,bZ]);
var aSubBVec = aVec.subtract(bVec);
var aSubCVec = aVec.subtract(cVec);
var n = aSubBVec.cross(aSubCVec);
```

So my new thought is to take the parameters I need, generate a string and use .expression to apply the expression. then selecting the properties and executing app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));

Now, this is all well and good, however, I would like the end result to be assigned values and not expressions.

So finally my question(s):

1) is cross and lookAt truly expression-only parameters?

2) is there a way once baked, to essentially "click" the stopwatch and kill all keys (i have seen for loops that remove keys from right to left but I don't want to introduce a performance hit especially when the value at each frame is indentical.

OTHERWISE:

3) is there a manual setup to the lookAt expression which I could replicate (with or without the Sylvester library.) I am assuming this is matrix multiplication (which is not in JS?, references and resources here would be greatly appreciated.)

4) OR is there a way to interrupt convert expression to keyframes after the first frame, then delete the key on the first frame.

lots of questions and maybe I'm not being terribly clear, any help would be greatly appreciated.