I’m a bit rusty, but I think that layerSpace transforms were not directly accessible in an extendscript, the way they are in expressions.
the workaround:
create a Null, apply an expression to it,
read the result of the expression and then set that as the anchorPoint.
(then throw away the null)
The expression would be:
thisComp.layer("center this").fromComp([thisComp.width,thisComp.height]/2);
–> layer “center this” would be the target
after you apply that value to your “center this” Layer,
it would of course also need to positioned in the center of your Comp.
Here’s an expression way to do that, because just setting it to [thisComp.width,thisComp.height]/2; would be wrong if the layer is parented.
if (hasParent) {
parent.fromComp([thisComp.width,thisComp.height]/2)
} else {
[thisComp.width,thisComp.height]/2;
}