• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to change the anchor point of a layer when clicking a button?

Explorer ,
Apr 28, 2019 Apr 28, 2019

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.

TOPICS
Scripting

Views

812

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 29, 2019 Apr 29, 2019

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.

Votes

Translate

Translate
Community Expert ,
Apr 29, 2019 Apr 29, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2019 May 04, 2019

Copy link to clipboard

Copied

Can you do this with percentages as well?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2019 May 04, 2019

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]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2019 May 04, 2019

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2019 May 05, 2019

Copy link to clipboard

Copied

LATEST

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines