Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Selecting and altering a text layer in a script

  • Selecting and altering a text layer in a script

    Posted by Dylan Winter on August 18, 2010 at 7:32 pm

    Hey guys,

    I’m a bit confused with the method by which one selects comps in Scripts versus expressions, but need to write as script to select a bunch of text layers and change their attributes. RIght now I have something similar to the code posted below, which In theory should select the 8th item down, then the first layer in that (a text layer), and then the value of its source text property– but apparently I’m getting the layer selection wrong. thisComp apparently doesn’t exist in scripting, and I’m not sure how to select the current comp without needing explicitly to select the comp I’m working in via activeItem since there are several comps with text layers that need to be changed in batches, and I’d prefer to ID them objectively through the script.

    Thanks for any insights you have!

    var textToEnter = prompt("Enter replacement text", "");
    app.project.item(8).layer(1).property("Source Text").value = textToEnter;

    Dan Ebberts replied 16 years ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    August 18, 2010 at 9:27 pm

    I haven’t test this, but it should be close:

    var textToEnter = prompt(“Enter replacement text”, “”);
    var myComp = app.project.item(8);
    var myTextLayer = myComp.layer(1);
    var mySourceText = myTextLayer.property(“ADBE Text Properties”).property(“ADBE Text Document”);
    var myTextDoc = mySourceText.value;
    myTextDoc.text = textToEnter;
    mySourceText.setValue(myTextDoc);

    Dan

  • Dylan Winter

    August 19, 2010 at 2:25 pm

    Hey Dan, thanks for the quick response!

    I tried the script you posted, but unfortunately it yields the same error message that mine did… that line four cannot be executed because null is not an object. I imagine that there’s something wrong with the way both of us are trying to access the text property of a layer, but I can’t seem to find clear documentation in the Scripting Guide on how to access a layer’s Source Text property.

    What weirds me out is that although the TextDocument object is defined as storing a layer’s Source Text property, it has an attribute (text) which stores the Source Text. What’s not clear to me is whether you can change the (… .value) of TextDocument or if that’s superseded by (… .text)

    There’s also the TextLayer object, which is a subclass of AVLayer and has its own properties (including Source Text).

    Clearly I still have a lot to learn about AE Scripting. I can’t thank you enough for your help (and website) though!

  • Dan Ebberts

    August 19, 2010 at 5:49 pm

    I just tried it, and it works fine for me. Is it possible that the 8th item in the project bin isn’t the comp where layer 1 is a text layer? I’d add a couple of alerts to make sure you’re getting that far:

    alert(myComp.name);

    after the declaration of myComp and

    alert(myTextLayer.name);

    after the declaration of myTextLayer

    Dan

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