Copy link to clipboard
Copied
Hi, my name is Bram and I'm from the Netherlands. I'm curious how to change the anchor point of a layer to a specified position when clicking a button.
I hope someone can help me out with this.
You can set the anchor point of a layer like this:
// Get Layer
var layer = app.project.activeItem.layers[1];
// 2D Layer
layer.transform.anchorPoint.setValue([100,100]);
// 3D Layer
layer.transform.anchorPoint.setValue([100,100,100]);
Put your anchor Point function inside of your onClick() event of your button and that's it.
Copy link to clipboard
Copied
You can set the anchor point of a layer like this:
// Get Layer
var layer = app.project.activeItem.layers[1];
// 2D Layer
layer.transform.anchorPoint.setValue([100,100]);
// 3D Layer
layer.transform.anchorPoint.setValue([100,100,100]);
Put your anchor Point function inside of your onClick() event of your button and that's it.
Copy link to clipboard
Copied
Can you do this with percentages as well?
Copy link to clipboard
Copied
Sure, you just do the math. If you want to center the anchor point, you can by dividing the width and height in half:
// Get Layer
var layer = app.project.activeItem.layers[1];
// 2D Layer
layer.transform.anchorPoint.setValue([layer.width*.5,layer.height*.5]);
Copy link to clipboard
Copied
It doesn't work on a text layer the same way as on a solid.
Do you know how to fix this?
Copy link to clipboard
Copied
Strange, sure someone else has the right answer, seems like this should work for text layers:
// Get Layer
var layer = app.project.activeItem.layers[1];
var textSize = layer.sourceRectAtTime(1, true)
var width = (textSize.width*.5)*-1;
var height = (textSize.height*.5)*-1;
// 2D Layer
layer.transform.anchorPoint.setValue([width,height]);
But it's slightly off. You can just use the Command ID instead with the layer selected:
app.executeCommand(10312);