Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Add markers to parented layers & selected

  • Add markers to parented layers & selected

    Posted by Ralph Moreau on March 26, 2022 at 5:57 pm

    Hi everyone working on a script. And my current iteration works, but it grabs every single layer that is parented and adds a marker. I’ve tweeked the for loop, and nested if statement but AE just ignores it. The script iterates through every single layer instead of only the selected. If by chance you could help here is my code.

    var comp = app.project.activeItem;


    for (i = 1; i <= comp.layers.length; i++) {


    if (comp.layers[i].parent != null) {


    var myMarker = new MarkerValue(comp.layers[i].parent.name);

    app.project.activeItem.layer(i).property("Marker").setValueAtTime(2, myMarker);


    }

    }


    }

    TempNull(); // add null

    };


    Ralph Moreau replied 4 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 26, 2022 at 6:26 pm

    So you want the marker if the layer has a parent and is selected, is that correct? This should work:

    var comp = app.project.activeItem;

    var mySelected = comp.selectedLayers;

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

    if (mySelected[i].parent != null) {

    var myMarker = new MarkerValue(mySelected[i].parent.name);

    mySelected[i].property("Marker").setValueAtTime(2, myMarker);

    }

    }

  • Ralph Moreau

    March 26, 2022 at 6:35 pm

    Hi Dan, thank you so much for your aid. In trying it out I received an error: “Function Array is undefined.”

  • Dan Ebberts

    March 26, 2022 at 7:43 pm

    I can’t think of a way you could get that error message. It works for me (although it could use some error checking to make sure a comp is actually selected). Did you run it the way I posted it, or did you make it part of something else?

  • Ralph Moreau

    March 27, 2022 at 12:42 am

    My mistake, thank you for graciously aiding me. This works perfectly. Thank you very much!

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