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

Simple Lower Third script

Explorer ,
Feb 14, 2021 Feb 14, 2021

Good Afternoon After Effects Community,

 

I'm building myself a generic Lower Third script for AE.  It creates a Generic string of Text (Lorem Ipsum) and creates a Shape Layer behind it.  The Generic Text is LEFT JUSTIFIED, but I have made a keyboardState for the SHIFT key.  When the SHIFT key is pressed, the Generic Text is created a RIGHT JUSTIFIED text layer.  I want to switch some the expression code attached to the Shape Layer so the sourceRectAtTime() will follow the text when it is RIGHT JUSTIFIED.  I'm not sure if I have quotes in the wrong place, if I need to do something with a String - just not sure how to make it an argument for the function.

 

I do not know how to create the arguments in the CREATE SHAPE Function I have coded to look changed the expression from  [l - p, t] to [w + l + p] to shift the Shape Layer Anchor Point from the left side of the shape layer to the right side of the shape layer.

 

Below is the CREATE SHAPE Function.  I made the type bold and it is near the bottom of the copied code. If I need to copy the whole script here, I can do that as well, just didn't want anyone to have to sift through the over 100 lines of code.  Let me know if you need to see the whole code.

 

Thanks in advance for any help.

 

//Create Shape Layer
function createShapeLayer(comp){
var shapeLayer = comp.layers.addShape();
shapeLayer.name = "LowerThirdBox";

var LowerThirdBoxGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
LowerThirdBoxGroup.name = "LowerThirdBox";
 
shapeLayer.property("Opacity").setValue(100);
shapeLayer.property("Anchor Point").setValue([0, 0]);

//Add expressions to follow Text Layer
var pathGroup = shapeLayer.property("Contents").property("LowerThirdBox").property("Contents").addProperty("ADBE Vector Shape - Rect");
pathGroup.property("Size").expression = "x = thisComp.layer(2).sourceRectAtTime().width; y = thisComp.layer(2).sourceRectAtTime().height; [x + thisComp.layer('Controls').effect('X Padding')('Slider'), y + thisComp.layer('Controls').effect('Y Padding')('Slider')]";
 
pathGroup.property("Position").expression = "var s = thisComp.layer(2); var w = s.sourceRectAtTime(s.outPoint).width/2; var h = s.sourceRectAtTime(s.outPoint).height/2; var l = s.sourceRectAtTime(s.outPoint).left; var t = s.sourceRectAtTime(s.outPoint).top; [w + l, h + t]";

var fillGroup = shapeLayer.property("Contents").property("LowerThirdBox").property("Contents").addProperty("ADBE Vector Graphic - Fill");
fillGroup.property("ADBE Vector Fill Color").expression = "thisComp.layer('Controls').effect('Main Box Color')('Color')";

LowerThirdBoxGroup.property("Transform").property("Anchor Point").expression = "var s = thisComp.layer(2); var w = s.sourceRectAtTime(s.outPoint).width; var l = s.sourceRectAtTime(s.outPoint).left; var t = s.sourceRectAtTime(s.outPoint).top; var p = thisComp.layer('Controls').effect('X Padding')('Slider')/2; [l - p, t]";

LowerThirdBoxGroup.property("Transform").property("Position").expression = "content('LowerThirdBox').transform.anchorPoint";

return shapeLayer;
}
TOPICS
Expressions , How to , Scripting
1.9K
Translate
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 , Mar 12, 2021 Mar 12, 2021

It's cause you were wrapping your variable justification in single quotes.

justintaylor_0-1615584252582.png

removed those and it works!

Translate
Community Expert ,
Mar 11, 2021 Mar 11, 2021

Your script works for me to generate a controllable box.

 

Regarding text alignment, that can't be changed with expressions so I'd suggest making layers for each alignment (left, middle, right), and then toggling their visiblility on and off with a Dropdown Menu Control.

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

Hey Justin - thanks for the reply.  I made 2 different variables to carry the whole (different) expressions.  Probably not the most practical way to handle it, but I coded the text to take a justification argument and then I plug in one of the two expressions as arguments to my Create Shape function.  I know there is a better way, just haven't figured it out yet.  Every time I try to replace  l- p with w + l + p, I get an error because the variable passes over the quotation marks in to the expression in AE and I have to go in a manually remove them.  Super frustrating.

 

Instead of the Dropdown Menu Control, I also made 4 Mogrts for Lower Left, Lower Right, Upper Left and Upper Right.  

 

Part of the code is below:

 

if(lowerRight){
var b = "var s = thisComp.layer('LOREM IPSUM'); var w = s.sourceRectAtTime(s.outPoint).width; var l = s.sourceRectAtTime(s.outPoint).left; var t = s.sourceRectAtTime(s.outPoint).top; var p = 30; [w + l + p, t]";

var d = "var s = thisComp.layer('LOREM IPSUM'); var w = s.sourceRectAtTime(s.outPoint).width/2; var h = s.sourceRectAtTime(s.outPoint).height/2; var l = s.sourceRectAtTime(s.outPoint).left; var t = s.sourceRectAtTime(s.outPoint).top; [w + l - (thisComp.layer('LowerThirdBox').effect('Outline Length')('Slider')/2), h + t]";

var myText = createTextLayer(ParagraphJustification.RIGHT_JUSTIFY, comp);
var myShape = createTextShapeRectangle(comp, "LowerThirdBox", "LowerThirdBox", b);
var myOutline = createOutlineShapeRectangle(comp, "Outline", "Outline", b, d);
var myMatte = createTextShapeRectangle(comp, "Matte", "Matte", b);
Translate
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 ,
Mar 12, 2021 Mar 12, 2021

It's a little hard to troubleshoot without the full code example, but we can take it one piece at a time. You mentioned getting an error when you 

 

replace  l- p with w + l + p. 

 

Are you saying you're trying to update an existing expression with a script and it's causing an error? If so can you post the before, after, and error you're running into?

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

It's around 290 lines of code now.  Basically about 140 lines with functions making up the rest.

Is that too much to dissect if I send the .jsx file along?

 

When the Lower Third is created on the left side, the final [x, y] is [l - p, t] (with all the sourceRectAtTime variables above that in the expression).

 

When the Lower Third is created on the right side, the final [x, y] needs to read [w + l + p, t].

 

I tried to make 2 variables, one with var xL = 'l - p' and one with var xR = 'w + l + p', but every time I try to subsititute it within the expression in the code, when it gets run in AE, the ' ' marks end up in the expression and the expression breaks.  I just need the ' ' marks to disappear.

 

It works when I have vectorLayerName = "LowerThirdBox" , because the quotes are needed.

vectorGroup.property("Transform").property("Position").expression = "content('" + vectorLayerName + "').transform.anchorPoint";
 
But I don't know how to get rid of the quotes (' ') when I just want the string to read l - p or w + l + p
 
Let me know if it's easier to post the whole script.

 

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

Yes just post the whole script and any instructions needed to generate the error (like what layers need to exist with what name and effects, etc). If you can just zip up a sample project file too that would be helpful.

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

Okay, I will try to recreate my error.  I've since added more and more to the script, so it's going to take a while to re-engineer it.  I will send along the script and a project with the expression errors.  Thank you for your help.

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

It wouldn't let me upload a .zip file.  Keeps giving me an error with the .aep and .jsx as well.  I have attached a .txt file for the script and a screenshot of one of the Anchor Point errors.  Is there another way to upload a .zip or .aep??? I've never tried to do that on this platform.

 

I made the .jsx a .txt.  You should just be able to copy and paste it and make .jsx or just change the .txt to .jsx and it should work.

 

You can place the script in ScriptUI Panels as there is a one button interface.  When you run the script, it will create the 3 layers (text layer, shape layer and matte layer).  The expression error is on the Shape Layer and Matte Layer on the Anchor Point.  You will see the 'l - p' at the end of the expression.  If you remove the quotes, the expression is fixed.  I just don't know how to code it so when the variable is written as a string, the quotes will not be transferred over to the expression, thus breaking the expression.

 

Let me know if you have any problems with the .aep or .txt.  Thank you in advance.

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

It's cause you were wrapping your variable justification in single quotes.

justintaylor_0-1615584252582.png

removed those and it works!

Translate
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 ,
Mar 12, 2021 Mar 12, 2021

GOOD GRIEF!!!!  Thank you. I could have swore I tried it that way and it was giving me an error still.  Thank you very much. I appreciate you taking the time to look at that for me.  

Translate
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 ,
Mar 12, 2021 Mar 12, 2021
LATEST

Sure thing, glad that worked!

Translate
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