Page 1 of 1

CS6 Javascript Properties?

PostPosted: 05/8/2015, 9:51 am
by Atom
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.
         alert(current_text);
         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?

Thanks!

Re: CS6 Javascript Properties?

PostPosted: 05/9/2015, 6:53 pm
by Penguino138
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!
-Nate