Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE Scripting: trying to edit text in a layer

  • AE Scripting: trying to edit text in a layer

    Posted by Rob Packer on November 9, 2021 at 1:12 pm

    Hi,

    I’m new to scripting in AE. So far have managed to create a dialog and get input, copy layers from another composition, copy the sourceText from that layer and make layers visible. I have text from an edittext field. In another script it can be set as the sourceText.

    I cannot seem to combine the imported layer text with the edittext field. Both are string values, so I am confused.

     

    The script included starts after the dialog declaration. This is the last piece in a bigger script.

    // assign values to the relevant compositions & setup global variables

    var compList = app.project.item(1); // composition with the list of cameras

    var compEditing = app.project.activeItem;

    var focalLen = “”;

    var zoomLen = “”;

    function setLens(){

    focalLen = ” @ ” + focalLength.text + “mm”;

    if(lens1.value == true){

    app.project.item(1).layer(11).copyToComp(compEditing); // layer 11 has the needed text

    var zoom = compEditing.layer(1).text.sourceText.value; // get text from the imported layer

    alert(zoom); // display the imported layer text

    // zoomLen = zoom + focalLen; // combine imported layer text with the focalLen text – fails here

    alert(zoom + focalLen); // display the focallen text – this also fails

    // alert(zoomLen); // display the combined impoted and focalLen text

    compEditing.layer(1).property(“Source Text”).setValue(zoomLen); // set the text for the layer to the combined value

    }

    compEditing.layer(1).enabled = true;

    }

    dialog.show();

    dialog.center();

     

    Any help would be appreciated.

    Blessings

    Rob

    Rob Packer replied 4 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    November 9, 2021 at 2:00 pm

    Hi Rob.

    Replacce var zoom = compEditing.layer(1).text.sourceText.value with var zoom = compEditing.layer(1).text.sourceText.value.text.

    Your code returns a variable that is of type TextDocument, not string. That variable also contains font, fontSize, fontFamily, text and other data.

  • Rob Packer

    November 9, 2021 at 9:26 pm

    Thanks Andrei!

    I figured it was something simple It works perfectly now.

    Rob

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