Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects script to create text layer with specified properties

Tagged: 

  • script to create text layer with specified properties

    Posted by oliver turm on February 1, 2024 at 10:39 pm

    Hi,

     

    I need to write a script which will create a text layer that:

    – is positioned in the lower left corner

    – displays the comp name

    – is white, with drop shadow, a specific font and size

    It all works fine until I get to the text properties and then I keep getting “unable to execute script at line #. undefined is not an object. I’ve tried both Bard and ChatGPT to help me figure this out but to no avail. Here’s what I’ve got

     

    var compName = app.project.activeItem.name;

    var textLayer = app.project.activeItem.layers.addText(“”); // Create with empty initial text

    var myTextDocument = new TextDocument(textLayer);

    myTextDocument.text = compName;

    myTextDocument.textProperty.fontSize = 30; // Set point size

    myTextDocument.textProperty.fillColor = [255, 255, 255]; // Set color to white

    textLayer.property(“Position”).setValue([50, app.project.activeItem.height – 50]);

    var dropShadow = textLayer.effects.addEffect(“Drop Shadow”);

    dropShadow.setProperty(“Color”, [0, 0, 0]);

    dropShadow.setProperty(“Opacity”, 50);

    dropShadow.setProperty(“Blur Radius”, 5);

    app.project.activeItem.selectedLayers = [textLayer];

     

    Thanks for any help.

     

    oliver turm replied 2 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Walter Soyka

    February 1, 2024 at 11:47 pm

    Text layers, text properties, and text documents can be a little tricky. You can read all about it in the docs here:

    https://ae-scripting.docsforadobe.dev/other/textdocument.html

    In the meantime, try this for your script:

    var compName = app.project.activeItem.name;

    var textLayer = app.project.activeItem.layers.addText(compName);

    var textProp = textLayer.property("Source Text");

    var textDocument = textProp.value;

    textDocument.resetCharStyle();

    textDocument.fontSize = 30;

    textDocument.fillColor = [1, 1, 1];

    textDocument.applyFill = true;

    textDocument.justification = ParagraphJustification.LEFT_JUSTIFY;

    textProp.setValue(textDocument);

    textLayer.property("Position").setValue([50, app.project.activeItem.height - 50]);

    var dropShadow = textLayer.property("Effects").addProperty("ADBE Drop Shadow");

    dropShadow.setProperty("Color", [0, 0, 0]);

    dropShadow.setProperty("Opacity", 50);

    dropShadow.setProperty("Blur Radius", 5);

    app.project.activeItem.selectedLayers = [textLayer];

  • oliver turm

    February 3, 2024 at 12:45 am

    I Walter, thanks so much for taking a look. That works great with the exception of the dropshadow. In other words, disabling the last 5 lines does exactly what I was after. I’ll take a closer look at the link you sent. Thanks again.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy