How do I auto displace position of objects based on text box width?

Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

Hi amazing scripters out there......... really hoping someone can help with this as it's been driving me nuts for days. As a novice scripter I just cant make this work.

 

I want to create a dynamic MOTGR file that contains one line of text between 2 objects. I want the Premiere user to be able to change the text, and the objects to push apart, or close together based on the length of the text they input.

 

Just based on centre text alignment is fine for now - but ideally it would be responsive whichever alignment is used.

 

I originally had a slider so they could manually alter the object positions after typing the text - but I want it to be more elegant than that.

 

I just can't seem to find an expression that works, so any help would be greatly appreciated.

 

Many thanks

 

Casey

TOPICS
Expressions , How to , Scripting

Views

67

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
community guidelines
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

There's literally hundreds tutorials and templates out there for this. Just do a search for sourceRectAtTime() or phrases like "background box adapting to text". Here's even a free script/ pseudo effect:

 

https://aescripts.com/textborder/

 

All that would be required would be to invert the logic and plug in or add the values of those bounding boxes to the other layers' positions, which would be no more difficult than linking a slider.

 

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
community guidelines
Community Beginner ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

Thanks for the quick response Mylenium.

 

Yes I saw those tutorial about dynamic boxes and have been trying to make those work - but - as I said - I'm a novice - and you lost me in your second paragraph......... "all that would be required........... hmmm - I get the theroy - but just cant write the code.... 🙂

 

CAsey

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
community guidelines
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

In the simplest form it could be something like this:

 

mText=thisComp.layer("Text");
mPos=mText.transform.position[0];
mWid=mText.sourceRectAtTime().width;
mPad=20 //padding/ spacing

X=mPos+mWid+mPad;
Y=value[1];

[X,Y]

 

This example assumes left aligned text and the code would be applied to the block after the text. The same methodology applies to any other scenario, but of course you may need to account for different text alignment options, anchor points and positioning of your text.

 

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
community guidelines
Community Beginner ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

Wow  ok - thanks Mylenium - I'm definitely going to give that a go - Its going to take me a little while to unwrap what youve written in order to make it work for center aligned text tho - and there is no way I couldve writtten this.

Thanks so much - really appreciate it.

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
community guidelines
Community Expert ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

The easiest way is to use my (paid) extension Pins & Boxes.

Just create pins for the corners of the text and parent the layers to the pins. The pins will stay at the corners of the text when the text changes and all layers parented to them will follow.

 

Note that you only need Pins & Boxes to create the rig. The mogrt you create will of course also work on machines where Pins & Boxes is not installed.

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
community guidelines
Community Beginner ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

LATEST

Thanks Mathias - looks very interesting - I'll check it out.

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
community guidelines