Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Use marker comments to parent layers back to their original parents

  • Use marker comments to parent layers back to their original parents

    Posted by Ralph Moreau on March 15, 2022 at 1:38 am

    Hi I’ve created a script that takes all layers that have a parent layer, then adds a marker to them using their parent layer name name. Then unparents them. I’m trying to create a script that does the reverse in a way;

    The script will look through the selected layers, find the marker name that coincides with their original parent layer and then reparents them back.

    Here is my current code which is the second part; the part that reconnects it. Please if someone could aid me.



    app.beginUndoGroup(“Null_Capture”);

    var comp = app.project.activeItem; // active comp

    if (comp instanceof CompItem) {

    for (i = 1; i <= app.project.activeItem.selectedLayers.length; i++) {

    if (comp.layer(i).property(“Marker”).keyValue(1).comment == comp.layer(i).name) {

    alert(“test works”);

    }

    }

    }

    app.endUndoGroup();

    Ralph Moreau replied 4 years, 2 months ago 2 Members · 7 Replies
  • 7 Replies
  • Filip Vandueren

    March 15, 2022 at 9:48 am

    I’m not a scripting expert but I think this works and is reasonably robust:

    app.beginUndoGroup("Null_Capture");
    var comp = app.project.activeItem; // active comp
    if (comp instanceof CompItem) {
    for (i = 1; i <= app.project.activeItem.selectedLayers.length; i++) {
    l = comp.layer(i);
    if (l.marker.numKeys) {
    c = l.property("Marker").keyValue(1).comment;
    l.parent = comp.layer(c);
    }
    }
    }
    app.endUndoGroup();
  • Ralph Moreau

    March 15, 2022 at 2:57 pm

    Incredible, thank you as always.

  • Filip Vandueren

    March 15, 2022 at 6:34 pm

    Oops, I think

    l=comp.layer(i);

    should be:

    l=comp.selectedLayers(i);

    Or it will be wrong when not all layers of the comp are selected when the script is run

  • Ralph Moreau

    March 15, 2022 at 7:44 pm

    Superb

  • Ralph Moreau

    March 16, 2022 at 6:39 am

    Filip thank you for your aid. In testing the script some more, now that new line comes with a new error – l=comp.selectedLayers(i); is sending error – “Function Array is undefined”. So I don’t know if this is the proper logic I put brackets around the iterating variable so it becomes an array – l=comp.selectedLayers[i]; .. But then the following code begins to break. Next line throws an error “undefined is not an object.”

  • Filip Vandueren

    March 16, 2022 at 10:13 am

    Sorry Ralph, you’re correct that it needed to be square brackets, but also we need to start counting from 0, since it is an array of layers, unlike After Effects’s built in methods like key() or layer() which start counting from 1.

    So, I hope this solves all problems:

    app.beginUndoGroup("Null_Capture");
    var comp = app.project.activeItem; // active comp
    var sl = app.project.activeItem.selectedLayers;
    if (comp instanceof CompItem) {
    for (i = 0; i < sl.length; i++) {
    var l = sl[i];
    if (l.marker.numKeys) {
    var c = l.property("Marker").keyValue(1).comment;
    l.parent = comp.layer(c);
    }
    }
    }
    app.endUndoGroup();
  • Ralph Moreau

    March 16, 2022 at 2:32 pm

    Understanding more of the behavior of this coding environment everyday . Very grateful for your direction! Thank you Filip.

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