eBox
Create and scale boxes from any anchor point with Expressions.
jsconst myBox = createBox({size: [100, 100],position: [0, 0],anchor: "center",});myBox.setScale([0, 100], "center");myBox.getPath();
The problem
When making templates in After Effects, you often need to create rectangles that have dynamic sizes and positions, like text boxes.
You can do this with rectangle shape or paths, using expressions to set their size, position and scale.
This gets complicated as you need to scale it on and off from different anchor points, with lots of nested Shape Groups or boilerplate code.
The solution
eBox solves this by providing an easy way to create box paths in expressions, where you can set the size, position and scale from any anchor point.
This allows you to create dynamic rectangle paths without any boilerplate code.
Usage
Import
Download the library .jsx file and import it into your After Effects project.
It's also a good idea to place the file in any compositions where it's used, so that After Effects will count it as used when reducing the project.
Reference the library
The library exposes a createBox function, which takes the box properties as an object parameters and returns a Box object.
jsconst { createBox } = footage("eBox.jsx").sourceData;
Create a box
You then use this function to create a box object, giving it the size, position and anchor properties of your box.
The anchor is the point of the box that will be at the given position.
jsconst myBox = createBox({size: [100, 100],position: div([thisComp.width, thisComp.height], 2),anchor: "center",});
Scale the box
You can then scale the box using it's setScale() method, from any anchor point.
jsmyBox.setScale([inScale, 100], "bottomLeft");myBox.setScale([outScale, 100], "bottomRight");
You can call setScale multiple times to control it from different anchor points. Each one scales the result of the previous scale operation, so the anchor points are always at the box corners.
Get the paths
You then call getPath on the box object, which returns the path value to set as the result of the expression.
jsmyBox.getPath();
API
Anchor
type
tsAnchor = "topLeft" | "topRight" | "bottomRight" | "bottomLeft" | "center";
Used in createBox and setScale to set anchor points.
createBox
function
tscreateBox(boxProperties: {size: [number, number] = [100, 100],position: [number, number] = [0, 0],anchor: Anchor = "center"}): Box;
Parameters
sizeThexandydimensions of the boxpositionThe position of the givenanchorin comp spaceanchorWhich point of the box should be at the givenposition
setScale
function
tsBox.setScale(scale: [number, number], anchor: Anchor): void;
Parameters
scaleThexandyamounts to scale, between0and100anchorWhere to scale the box from
getPath
function
tsBox.getPath(): PathValue;
Returns the path value of the box after scaling, to be used as the result of an expression on a path property.
Checking the version
All of our libraries expose a version string you can use to check if it's up to date:
jsthrow footage("lib.jsx").sourceData.version;