Skip to main content
Inspiring
July 19, 2023
解決済み

An explanation of the behavior of the program is required

  • July 19, 2023
  • 返信数 1.
  • 626 ビュー

Hi all.
The project (Test.aep) contains one composition with one layer.
This layer has a mask in add mode that selects a small part of the layer.

drawing t1.png

If you do the following in manual mode:
1. Using the Anchor Point layer parameter, place the area with the mask in the center of the composition.
figure t2.png
2. Resize the composition so that it contains only the area selected by the mask.
Composition menu / Composition parameters .... pictures t3.png, t4.png

Then we get the state of the scene> t5.png

I assumed that the code below will repeat what was done in manual mode.

app.project.activeItem.layer(1).selected = true;
app.project.activeItem.layer(1).transform.anchorPoint.setValue([1239.5, 368.0]);
app.project.activeItem.width = 130
app.project.activeItem.height = 135

But scene state > t6.png

Is there a way, using a script, to come to the state of the scene t5.png

このトピックへの返信は締め切られました。
解決に役立った回答 Paul Tuersley

The reason is, if you look in the advance tab of the composition settings, you'll see you can choose where it resizes the comp around. It defaults to center. As the co-ordinate system is based on zero at the top left, it then has to adjust all the position values so it is centered in the resized comp.

 

Scripting doesn't do that automatically, you're literally just telling it to change the comp size, so all the position values stay unchanged and relative to the original comp size. So you need to offset the Position values by half the difference between the original comp size and the new comp size.

 

You started with a 1925x1080 comp with a Position value of 962.5, 540.

You ended up with a 130x135 comp with a Position value of 65,67.5

 

Half the difference for comp size is:

x: 1925-130=1795 / 2 = 897.5

y: 1080-135=945 / 2 = 472.5

 

So you need to offset the Position:

x: 962.5-897.5 = 65

y: 540-472.5 = 67.5

 

 

 

返信数 1

Paul Tuersley解決!
Inspiring
July 19, 2023

The reason is, if you look in the advance tab of the composition settings, you'll see you can choose where it resizes the comp around. It defaults to center. As the co-ordinate system is based on zero at the top left, it then has to adjust all the position values so it is centered in the resized comp.

 

Scripting doesn't do that automatically, you're literally just telling it to change the comp size, so all the position values stay unchanged and relative to the original comp size. So you need to offset the Position values by half the difference between the original comp size and the new comp size.

 

You started with a 1925x1080 comp with a Position value of 962.5, 540.

You ended up with a 130x135 comp with a Position value of 65,67.5

 

Half the difference for comp size is:

x: 1925-130=1795 / 2 = 897.5

y: 1080-135=945 / 2 = 472.5

 

So you need to offset the Position:

x: 962.5-897.5 = 65

y: 540-472.5 = 67.5