Highlighted

"can't turn value into number" when selecting rectangle's size with an expression

New Here ,
Oct 23, 2020

Copy link to clipboard

Copied

hi everyone ! 

I've been struggling with an issue that i can't find a fix for.

I am trying to reuse the size of a rectangle to determine the position of another element in my scene, using expressions. (I am making a lower thord template that resizes automaticlly with the text tou type in)

I am using this expression : 

w = thisComp.layer("RECTANGLE BLANC").content("Rectangle 1").content("Tracé rectangulaire 1").size[0];

thisLayer.xPosition = thisComp.layer("RECTANGLE BLANC").xposition + w/2;

Even if "w" is defined, and contains something like 399.2948496165198 (i've used throw new Error() to debug), AE sends me this error : "can't turn value into number" (translated from french) at the fisr line of my expression.

I've tried to parse, to floor, but nothing seems to work.. 

Does anyone have any suggestions ? 

TOPICS
Error or problem, Expressions

Views

39

Likes

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

"can't turn value into number" when selecting rectangle's size with an expression

New Here ,
Oct 23, 2020

Copy link to clipboard

Copied

hi everyone ! 

I've been struggling with an issue that i can't find a fix for.

I am trying to reuse the size of a rectangle to determine the position of another element in my scene, using expressions. (I am making a lower thord template that resizes automaticlly with the text tou type in)

I am using this expression : 

w = thisComp.layer("RECTANGLE BLANC").content("Rectangle 1").content("Tracé rectangulaire 1").size[0];

thisLayer.xPosition = thisComp.layer("RECTANGLE BLANC").xposition + w/2;

Even if "w" is defined, and contains something like 399.2948496165198 (i've used throw new Error() to debug), AE sends me this error : "can't turn value into number" (translated from french) at the fisr line of my expression.

I've tried to parse, to floor, but nothing seems to work.. 

Does anyone have any suggestions ? 

TOPICS
Error or problem, Expressions

Views

40

Likes

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
Oct 23, 2020 0
Most Valuable Participant ,
Oct 23, 2020

Copy link to clipboard

Copied

Your code is nonsense. Your "thisLayer.xPosition =" makes absolutely no sense. You don't assign values to property streams, you apply the expression to the property stream. That and of course JavaScript is case-sensitive, so your expression would fail a second time because you have a typo. Simply apply the cleaned-up code directl to the Position property:

 

mRect=thisComp.layer("RECTANGLE BLANC");
w=m.content("Rectangle 1").content("Tracé rectangulaire 1").size[0];

mRect.xPosition + w/2;

 

Mylenium

Likes

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
Reply
Loading...
Oct 23, 2020 0
New Here ,
Oct 23, 2020

Copy link to clipboard

Copied

Tanks for the "nonsense" and the aggressivity. I'm trying my best here but AE coding system is not really userfriendly for a guy coming form software development 🙂

 I figured it out myself. And just for fun, your code doesn't work because "m" is not defined line two. I guess you meant "mRect", but it doesnt work either, i get the exact same error as before.

 

Next time try being a little less aggressive maybe ? Especially when your solution doesnt work.

 

cheers

Likes

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
Reply
Loading...
Oct 23, 2020 0
Most Valuable Participant ,
Oct 23, 2020

Copy link to clipboard

Copied

Didn't mean to be agressive in any way. Yeah, made a typo/ omission myself without noticing it. Otherwise no point in getting worked up. Misunderstandings happen all the time and I'm not always near AE. From your code I was simply assuming you were referencing the xPosition property of a 3D layer, which is the only place where xPosition even occurs. Here's something that should work correctly.

 

mRect=thisComp.layer("RECTANGLE BLANC");
w=mRect.content("Rectangle 1").content("Tracé rectangulaire 1").size[0];

[mRect.transform.xPosition + w/2,value[1],value[2]);

 

Again, apologies for the inconvenience.

 

Mylenium

Likes

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
Reply
Loading...
Oct 23, 2020 0
Adobe Community Professional ,
Oct 23, 2020

Copy link to clipboard

Copied

The latest versions of AE autocompletes all of the AE specific language and any variables you put in your expression. If typing xposition doesn't bring something up then the reference is meaningless and will throw an error.

 

If you want to get the size of a rectangle and it is a parametric shape then the X and Y values are available in the array. If the rectangle is a vector path then you can either use sourceRectAtTime() to calculate the size or attach a null to each vertex using the Create Nulls from Paths/Nulls follow Paths Script and calculate the distance between the nulls.

 

Creating a rectangle that automatically resizes and changes position based on the characters in a text layer should also be tied to shape layer position, the Rectangle Position, anchor point, the scale of the layer, and probably a bunch of other factors. Just pulling the position of the shape layer can be meaningless unless you also consider every other transform property available in a shape layer.

 

What are you trying to re-position? What does your comp look like? The only thing your expression will do when you fix the errors is to return half the width of a parametric rectangle. If the Rectangle is on another layer this is all the code you need:

 

rectWidth = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[0] / 2;

 

If you want that information to position another layer and keep it lined up with the rectangle then you need to at least consider these other variables. 

Screenshot_2020-10-23 10.02.05_p9WLz0.png

This is what is required to keep a shape layer rectangle lined up with some text.

Screenshot_2020-10-23 10.29.01_vHSOBQ.png

I've got padding sliders adjusted, The top text layer and the bottom text layer are both reading the same property, but because of Rendering Order, the top text layer is showing 500 for width because that's what I set the Rectangle to when I was creating this preset. The bottom text layer reads the width of the rectangle after the expression does its job.

 

Tell us what you are trying to do and we can help. Mylenium's rebuff makes sense to me - your code makes no sense at all and you have not taken the time to read any of the expression language reference materials. 

Likes

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
Reply
Loading...
Oct 23, 2020 0