Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Find selected Layers with part of name.

  • Find selected Layers with part of name.

    Posted by Fabian Brugger on February 6, 2023 at 10:29 am

    Is it possible to get to all selected layers that have, for example, the name scale in its name.

    So the layer would be called something like: Frame1_Icon1_Scale

    And i want to find all layers with the ending Scale or with Scale in its name anywhere (whatever is possible) to animate it through a script.

    I write this but it just finds the exact name:

    var comp = app.project.activeItem;

    var layers = comp.selectedLayers;

    for (var i = 0; i < layers.length; i++) {

    if (layers[i].name = “scale”) {

    var scalelayerkeys = layers[i].property(“Transform”).property(“Scale”)

    scalelayerkeys.setValueAtTime(0,[0,0]);

    scalelayerkeys.setValueAtTime(0.4,[110,110]);

    scalelayerkeys.setValueAtTime(0.7,[100,100]);

    }

    }

    Fabian Brugger replied 3 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    February 6, 2023 at 1:28 pm

    try:

    if (layers[i].name.indexOf("scale")>-1) {

    or for case insensitive matching:

    if (layers[i].name.match(/scale/gi)!==null) {
  • Fabian Brugger

    February 6, 2023 at 1:45 pm

    The .indexOf version does exactly what i want.

    But will use the one with case insensitive matching so it has less possibilities for errors

    Thank you!

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