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

Expression error on the position of the anchor point

Explorer ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Hello ! I am a beginner in expressions, and to learn and understand I practice expressions like this found on School of motion

 

a=thisComp.layer("Text").sourceRectAtTime();

height=a.height;

width= a. width;

top=a.top;

left=a.left;

x=left;

y=top+height

[x,y];

This code should fix the anchor point at the bottom left of the text layer, but AE sends me back:

Error at line 8 in the “anchor point” property of the layer (“Text”) in the composition 6. property or method named “y” in the class “global” not found or non-existent ...

Can you tell me why?

TOPICS
Error or problem , Expressions

Views

3.0K

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 , Apr 02, 2020 Apr 02, 2020

You left the semicolon off the end of line 7 so y was never defined. Nothing but a typo.

 

if you the layer reference to thisLayer you won't have to worry about the text layer name. There is also no need to define the width. I have a similar expression saved as an animation preset:

 

txtLyr = thisLayer.sourceRectAtTime();
height = txtLyr.height;
top = txtLyr.top;
left = txtLyr.left;
x = left;
y = top + height;

[x,y]

 

 That's a little cleaner and you never have to worry about the layer name.

 

Votes

Translate

Translate
Community Expert ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

You left the semicolon off the end of line 7 so y was never defined. Nothing but a typo.

 

if you the layer reference to thisLayer you won't have to worry about the text layer name. There is also no need to define the width. I have a similar expression saved as an animation preset:

 

txtLyr = thisLayer.sourceRectAtTime();
height = txtLyr.height;
top = txtLyr.top;
left = txtLyr.left;
x = left;
y = top + height;

[x,y]

 

 That's a little cleaner and you never have to worry about the layer name.

 

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
Explorer ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Thank you very much ! i will pay attention to that now

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
Valorous Hero ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Rick, the Text Layer must be referenced cos I'm quite certain OP wants to create an auto resizing Shape Layer that's linked to a Text Layer.

Also, this is a lot cleaner -

 

a=thisComp.layer("sdfsdf sdfsdf").sourceRectAtTime();
[a.width,a.height]

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

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

Copy link to clipboard

Copied

Roland, My expression (and preset) is designed to put the Anchor Point of a text layer in the bottom left corner of the text layer. That's what the OP was trying to do. His expression clearly points to thisLayer.

 

When I want to line up a shape layer with the text layer as you suggest he might want to do, I always snap the anchor point to the bottom of left corner of the text area. The [a.width, a.height] expression will only give you the size of the text area and that is useful for sizing the rectangle, but you need anchor point and position of the text layer to get the box to stick to the text. 

 

When I am creating a shape layer to go behind text I always use direct references in my expressions because the shape layer will usually be below the text layer. I use an expression to center the anchor point in the text area more often than the one I shared that puts the anchor point at the bottom left. Then it never matters how the text is justified.

 

Here are my two most used animation presets for creating MOGRT files:

https://www.dropbox.com/s/5cxexyecurx9css/magic%20text%20box.ffx?dl=0

and:

https://www.dropbox.com/s/zs8k2643qfht86g/center%20anchor%20point.ffx?dl=0

 

The center anchor point preset uses this expression:

txtLyr = thisLayer.sourceRectAtTime();
hlfHt = txtLyr.height/2;
top = txtLyr.top;
cntr = txtLyr.left + txtLyr.width/2;
x = cntr;
y = top + hlfHt;

[x,y]

The Magic Text Box preset uses these expressions and adds a slider control for padding:

// Rectangle size
txt = thisComp.layer(index - 1);
s = txt.sourceRectAtTime();
pad = effect("Padding")("Slider");
[s.width, s.height] + [pad, pad]

//Transform Rectangle Anchor Point
[0, 0]

//Transform Rectangle Position
[0, 0]

//Transform Anchor Point
[0, 0]

//Transform Position
txt = thisComp.layer(index -1).position

All you have to do is type anything in a new text layer, apply the Center Anchor Point preset, deselect the layer and double click the Magic Text Box expression to add a new shape layer that will snap into position under the text as soon as you move it below the text layer. Takes about 10 seconds.

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
Valorous Hero ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Thanks for the clarification Rick - it does look like OP wants to place a Text Layer's anchor point at the bottom left. I've done these many hundreds of times, literally, over the past many months and I say with confidence that EVERYONE that I have seen do this sort of auto alignment and auto-resizing is doing it either totally or partially wrong..

This code does the trick (to place a Text/Shape Layer's Anchor Point at its bottom-left, with two lines of code) 

a = thisLayer.sourceRectAtTime();
aBL = [a.left,a.top+a.height]

Those keen to see what's actually viable with sourceRectAtTime and other AE Expression methods should download these Responsive Design MoGraphs to have a better idea how ALL MoGraphs will/should be created now or at least, in the near future. THIS IS NOT RESPONSIVE DESIGN TIME. And this is not what you will see at Adobe's official demos of MoGRTs that continually show very basic implementation of MoGRTs since its inception.

So ... I've spent some time developing true Responsive Design AE-MoGRTs so that others may be inspired to produce the same and/or even better results.

April Responsive Design MoGraph Freebie
https://gumroad.com/products/tbIsF

Responsive Design Broadcast Toolkit
https://gumroad.com/products/sYeMm

Responsive Design Ticker Tape Animation
https://gumroad.com/products/iMjIb/

 

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

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 Beginner ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Hello Rick,

 

I'm trying to animate in and out with the same text layer and i have managed to (more or less) achieve it but i got stucked in a problem.

 

Because in my language we use a few special characters i used an absolute value for height and because i wanted the shape (BARRA)  to be longer than the text i have incremented the width in 60px. And finally because i want the shape to start one frame before the text i used the time inpoint of text.

Is working fine. as i wanted it to be.01.JPG

Then, i have decided that i want to animate out with the same layer and logic, so i had thought that all i needed was to chanche the anchor point for the duplicated shape (BARRA 2) and the animation for the text. And i did it.

I had to align the shape to the same position as the previous one and it worked.

2.JPG

 

My problem is that it works only with that exact text. When i try to change the text, as the text is justified left it will start from that point as the shape starts from the other side.

 

So it works but doesn't help my needs witch are copy/paste text + animate in and out with minimum steps.

Is there a solution for this ? Is it possible to make a shape's position floating to the last character of a sentence ? or some other path to find a solution ?

 

(i am new and i dont't know if it is correct to post this in here or if i should start a new thread. If that's the case please ask me and i will do so)

 

thanks

*

i

 

 

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 Beginner ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

LATEST

is it something as txt.length ?

and as the shape position is defining the anchor i need to use the layer position?

but i can´t write the sintaxe

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