How to set the opacity of every text layers to 0 and time vary stop watch activated ?

What type of scripts do you need?

Moderator: byronnash

Post Reply
MikeA
Posts: 1
Joined: June 22nd, 2018, 6:50 pm

Hi everyone !

I'm doing an amateur Adobe After Effects project and I wanted to learn how to script.
Basically I want to set the opacity of every text layers to 0 with time vary stop watch activated.

I'm sure the following script is wrong but here is my first AE scripting attempt of my life :

Code: Select all

var textLayers = app.project.layers.items.TextLayers

for textLayer in textLayers{
        textLayer.opacity = 0;
    }
Can you help me with this first script so I can learn how to do them for next time?
User avatar
zlovatt
Posts: 47
Joined: October 31st, 2016, 5:00 pm
Location: Portland
Contact:

Hi!

This is how I'd do it. Note that this doesn't do any error checking (it doesn't check that a comp exists, or that there are any layers, or that there aren't keyframes) -- but for a really simple first pass, this should work!

Code: Select all

(function () {
  // Get the active composition
  var comp = app.project.activeItem;

  // Get layers in the comp
  var layers = comp.layers;

  // Create an "Undo Group", so every action between this and app.endUndoGroup()
  // can be undone in a single stage
  app.beginUndoGroup("Set TextLayer Opacity to 0");

  // Loop through all of the layers
  for (var i = 1, il = layers.length; i <= il; i++) {
    var layer = layers[i];

    // If the current layer isn't a text layer, skip it
    if (!(layer instanceof TextLayer))
     continue;

    // Set the layer's opacity to 0
    layer.opacity.setValue(0);
  }

  app.endUndoGroup();
})();
Let me know if this helps, or if you have any questions!
Post Reply