CS6 Javascript Properties?

Scripting for After Effects

CS6 Javascript Properties?

Postby Atom on 05/8/2015, 9:51 am

Hi All,

I have a bunch of text layers that are animated. I need to change the source text of each layer to a new value. I want to do this using Javascript (NOT EXPRESSION).

My code currently looks like this.
Code: Select all
      for (var k=1; k<=selLayers.length; k++)    // go through selected layers one at a time
         curLayer = comp.layers[k];

         // Search for existing copy to replace.
         current_text = curLayer.property("sourceText");
         //current_text = curLayer.sourceText    //CS3 style.
         if (current_text == "OLD COPY")
            current_text.setValue("NEW COPY");
            alert ("found it");

This does not seem to work even though I have the text layer selected. When I alert the current text it displays 'UNDEFINED'.
What is the correct way to fetch and set text using Adobe Javascript?

After Effects CS3, CS5, CS6
Windows 7 x64, OSX 10.6.8
Blender 3D
Posts: 178
Joined: 02/3/2010, 7:24 am

Re: CS6 Javascript Properties?

Postby Penguino138 on 05/9/2015, 6:53 pm

By not using an expression I think you mean a script?

Here are some modifications I made to your code to make it work in a .jsx script:
Code: Select all
      var comp = app.project.activeItem;
      var selLayers = new Array(0);
      selLayers = comp.selectedLayers;

      for (var k=0; k<selLayers.length; k++)    // go through selected layers one at a time
         var curLayer = selLayers[k];
         // Search for existing copy to replace.
         var currentText = curLayer;
         if (currentText.name == "OLD COPY")
            textValue = "NEW COPY";
            curLayer.property("Source Text").setValue("NEW COPY");
            curLayer.name = "NEW COPY";
            alert ("found it");

NOTE: this script requires you to have your comp AND layers selected. If you want to change the text they change to, simply change the script anywhere it says "NEW COPY"

If you have any questions let me know!
Posts: 230
Joined: 04/26/2011, 9:36 pm
Location: Idaho, US
Twitter: @natelovell99

Return to After Effects Expressions