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

Create a flexible frame in after effects

New Here ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

Hi there, 

 

I've been struggling for two days now trying to figure out how to create a flexible frame/container, with it's size deterimined by two seperate shapes.  I've found loads of tutorials on flexible text frames using the sourceRectAtTime expression,  though nothing on just shapes. After some thought and playing around I applied the trasnform.position to my container rectangle using one of the other shape's (the blue square) position, which seems to have got me a step closer, though still not quite right. See the gif below. 

 

container-test3.gif Ideally, I would like the red rectangle to act as the 'container' for my two squares. The strokes represent the padding I would like on each of the smaller squares.  I'm still kinda new to expressions and have been trying to learn as I go, but this one has me stumped on how to write it.

I suspect I need to define:

  • one square as my red rectangle's width and the other for the height
  • include a max value and min value to prevent the red rectangle shrinking past the smaller squares

 

Below is a screen grab of my layers for reference. 

 

Screenshot 2020-08-21 at 15.23.19.png

 

I did try a version where I've done everythihg manually, though this is not practical and not as accurate as I would like it to be. Any help would be greatly appreciated! Please! I beg of you After effects community of awesomeness! 

TOPICS
Expressions , How to

Views

431

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 , Aug 21, 2020 Aug 21, 2020

If your two small box layers have the anchor point at the center of the square, and the size of the slave box is tied to the size of the master box, then you can add an expression that takes the size of the master square and the position difference between the two squares to calculate the size of the background container rectangle. You'll also need to add an expression to the Position property of the controller layer that adds 1/2 of the position value for the master and slave box to calculate t

...

Votes

Translate

Translate
LEGEND ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

It's just a simple addition of all the values, with teh only caveat being that comp positions are calculated from the top left corner whereas shape layers have their origin in the middle, so you always need to subtract half the comp width and height. that and of course you would have to calculate the center between the two rectangles if they don't move symmetrically, which is also merely a case of subtracting and adding positional differences and adding another expression to the actual rectangle position.

 

Mylenium

 

 

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
New Here ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

LATEST

Thank you!

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 ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

If your two small box layers have the anchor point at the center of the square, and the size of the slave box is tied to the size of the master box, then you can add an expression that takes the size of the master square and the position difference between the two squares to calculate the size of the background container rectangle. You'll also need to add an expression to the Position property of the controller layer that adds 1/2 of the position value for the master and slave box to calculate the new position of the container. An if/else argument needs to be in place to prevent negative numbers. That would give you a comp that looks something like this:

Screenshot_2020-08-21 13.28.40_iB4eTn.png

These are the expressions for the container layer:

 

// Rectangle 1/ Size
corner1 = thisComp.layer(index -2);
corner2 = thisComp.layer(index - 1);
cornerComp = corner1.content("Rectangle 1").content("Rectangle Path 1").size[0]
pad = effect("Pad")("Slider") + cornerComp;
boxH = corner1.position[1] - corner2.position[1];
boxW = corner1.position[0] - corner2.position[0];
if (boxH < 0)
	ySize = - boxH
else
	ySize = boxH;
if (boxW < 0)
	xSize = - boxW
else xSize = boxW;

boxSize = [xSize + pad, ySize + pad]

//Container Layer/Position
mstr = thisComp.layer(index - 2).transform.position / 2;
slave = thisComp.layer(index - 1).transform.position / 2;
mstr + slave

 

If you want to have the corner boxes be anything but square you'll have to separate out height and width and make those compensations in the calculations.

 

It should go without saying that the Rectangle 1/Transform Rectangle 1/ properties should all be at their default values of 0 and 100% for scale. 

 

The size of the slave box just needs to be tied to the size of the master box with a simple pickwhip expression like this:

 

thisComp.layer(index -1).content("Rectangle 1").content("Rectangle Path 1").size

 

When I'm writing expressions that I might save as animation presets I always use the index value instead of the layer name so I don't have to dig around and rename things, I just have to put the layers in the right order. 

 

I hope this helps. If you wanted to get really fancy you could even modify these expressions and make them work with 3D shape layers.

 

You could also put everything on a single shape layer and animate the Rectangle/Transform Rectangle position properties to move the master and slave corner boxes. The same idea applies to the size and position expression to keep things lined up. 

 

Here's the project file for the screenshot. I liked the idea so I saved an animation preset. I'm now up to over 100 presets that I have created for shape layers.

Contaianer.gif

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
New Here ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

Thank you so much, you have saved my bacon! And thank you for sharing the file!

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