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

expression result must be of dimension 2 not 1 error

New Here ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

I'm trying to write an expression that determines the size of a path based on the width of two text layers.

However, I also don't want it to be less than 750 pixels wide.  My first expression seems to work just fine, but when I try to use an if/else statement, I suddenly get an "expression result must be of dimension 2 not 1" error on my first line.  What am I missing?

 

This expression seems to work:

 

var s = comp("Talent Name Precomp").layer("First Name");
var w = s.sourceRectAtTime().width;
var ss = comp("Talent Name Precomp").layer("Last Name");
var ww = ss.sourceRectAtTime().width;


[w+ww+80,0];

 

This one gives me an error:

 

var s = comp("Talent Name Precomp").layer("First Name");
var w = s.sourceRectAtTime().width;
var ss = comp("Talent Name Precomp").layer("Last Name");
var ww = ss.sourceRectAtTime().width;


if(w+ww+80<750){
750;
}else{
w+ww+80;
}

TOPICS
Error or problem , Expressions , Scripting

Views

6.6K

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
Mentor ,
Aug 03, 2020 Aug 03, 2020

Copy link to clipboard

Copied

Some proberties in AE need an array of two values (even 3 or 4, depending on the proberty).

You didn't tell us, where you use this expression, but if you get this error, it's because the final result of your 2nd expression is just one value (750, or w+ww+80).

In your first expression, the final result was an array of two values, namely w+ww+80 and 0.

 

So, the fix is just to add the missing value in your 2nd expression:

 

if (w+ww+80 < 750){
       [750, 0];
} else {
      [w+ww+80, 0];
};

 

*Martin

 

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

Copy link to clipboard

Copied

You have not completed the array after the if statement.

 

 

if (w + ww + 80 < 750)
     x = 750
else
    x = w + ww + 80;

[x, value[1]]

 

The if statement declares that if the combined values are less than 750 then the new variable "x" equals 750, but if the combined values are less than 750 the variable "x" is not the combined values of the values. 

 

The array then uses the variable as x for the first value and the current value of the second part of the array, the Y value, as the Y value. This would allow you to set the second value or the height in your path. 

 

I am assuming that you are using a shape layer rectangle for the path because a path does not have a width or height. I also assume that you do not need the height of the lines of text because you have not mentioned them.

 

If the property you are modifying is an array then you need an array as the result.

 

If you allow the new Expression engine to help you write the if statement it will do the indenting and you can leave off the brackets. The code is a little easier to read and the only thing you need is the ; at the end.

 

The only time you need to use an opening and closing bracket is when you have more than one thing going on in the results section.  For example, this requires an opening and closing bracket in the if portion of the expression:

 

if (x == 0) {

     newX = 10;

     final x = newX / thisComp.width;

}

else

     newX = 100;

[newX, value[1]]

 

 

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
Enthusiast ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

Just to add to the other replies, you can also replace the if statement with:

Math.max(w+ww+80,750); // returns highest of two values

 

or in your case:

[Math.max(w+ww+80,750), 0];

 

or if you want both dimensions the same rather than the second being 0:

var result = Math.max(w+ww+80,750);

[result, result];

 

or you want the second dimension to stay as current value:

[Math.max(w+ww+80,750), value[1]];

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

Copy link to clipboard

Copied

LATEST

As Paul said, for this particular expression the best solution is

var s = comp("Talent Name Precomp").layer("First Name");
var w = s.sourceRectAtTime().width;
var ss = comp("Talent Name Precomp").layer("Last Name");
var ww = ss.sourceRectAtTime().width;

[Math.max(w+ww+80,750),0]

 

Extra Tip:
My extension Pins & Boxes offers very easy and powerful solutions for these kinds of layout problems. You don't need to write any expressions yourself and can easily create shapes around multiple texts:

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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