change multiple text in multiple comps

Scripting for After Effects

change multiple text in multiple comps

Postby ha2_ on 06/1/2015, 6:21 am

hi,
I am new in scripting. I want make script that can do simple replace text like this.
I have 10 comps and inside each one 3 text layers.
I know names of comps and names of layers so I need something like this.

open GUI with button
Code: Select all
var myWin = new Window("palette", "My Window", undefined);

var groupOne = myWin.add("group", undefined, "GroupOne");
        groupOne.orientation = "column";
        groupOne.add("button",undefined, "Button");


on click do this

Code: Select all
comp("Comp 1").layer("text 1").settext("my text");
comp("Comp 1").layer("text 2").settext("another text");
comp("Comp 1").layer("text 3").settext("mega text");

comp("Comp 2").layer("text 1").settext("batman");
comp("Comp 2").layer("text 2").settext("superman");
comp("Comp 2").layer("text 3").settext("megaman");

comp("Comp 3")......


I know replace layers with this code

Code: Select all
var theComposition = app.project.item(1);
var theTextLayer = theComposition.layer('text');
theTextLayer.property("Source Text").setValue("This text is from code");


But i don't know how tell to script don't use active comp but other comps.
Thx
ha2_
 
Posts: 14
Joined: 04/14/2013, 4:06 am

Re: change multiple text in multiple comps

Postby Penguino138 on 06/9/2015, 9:35 am

I am at work so I do not have ExtendScript and I ended up coding this in Notepad++, but the code below should do what you want:

Most of the script is completely automated. The only things you will need to change is the textReplace variable, as wells as the names of the comps and text layers that are in if statements below. Other than that it should work. Let me know if something does not or if you have any questions.

Code: Select all
var curProj;
var compArray = new Array();
var textArray = new Array();
var curItem;
var curComp;
var curLayer;
var curText;
// input the text you want to replace the text layers with in the var textReplace
var textReplace = ;

var myWin = new Window("palette", "My Window", undefined);

var groupOne = myWin.add("group", undefined, "GroupOne");
      groupOne.orientation = "column";
      var button = groupOne.add("button", undefined, "Button");
      
   button.onClick = function(){
      
      // look through project window for comps that are named comp 1, comp 2, or comp 3. Then store them in an array
      for(var i; i <= curProj.numItems; i++){
       curItem = curProj.item[i];
         if((curItem instanceof CompItem) && curItem.name == "Comp 1" || "Comp 2" || "Comp 3"){
            compArray.push(curItem);
         }
      }
      
      // look through our found comps for text layers that are called text 1, text 2, or text 3. Then store those into an array
      for(var t = 0; t < compArray.length; t++){
         curComp = compArray[t];
            for(var a = 1; a <= curComp.numLayers; a++){
               curLayer = curComp.layer(a);
                  if((curLayer instanceof TextLayer) && curLayer.property("Source Text") == "Text 1" || "Text 2" || "Text 3"){
                     textArray.push(curLayer);
                  }
            }
      }
      
      // sets all the text layers gathered = to textReplace
      for(var k = 0; k < textArray.length; k ++){
         curText = textArray[k];
            var textProp = curText.property("Source Text");
            var textDocument = textProp.value;
            textDocument.text = textReplace;
            textProp.setValue(textDocument);
      }
   
   }


-Nate
Penguino138
 
Posts: 230
Joined: 04/26/2011, 9:36 pm
Location: Idaho, US
Twitter: @natelovell99

Re: change multiple text in multiple comps

Postby ha2_ on 06/11/2015, 2:38 pm

I can't try it yet but, yes, this seems exactly what i want :) Thx!
ha2_
 
Posts: 14
Joined: 04/14/2013, 4:06 am


Return to After Effects Expressions

cron