Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Parent Un-Partented Nulls – A Script I would love!

  • Parent Un-Partented Nulls – A Script I would love!

  • Laurie Gibbs

    January 21, 2022 at 11:05 am

    I would really like a script that can look at all selected layers, then parent all of the layers which don’t currently have a parent layer to a new null.

    Ideally the null would be created at an average position to the selected layers.

    This would be really useful for instantly creating parent nulls without disrupting existing hierarchy.I would love a script that can look at all selected layers, then parent all of the layers which don’t currently have a parent layer to a new null.

    Ideally the null would be created at an average position to the selected layers.

    This would be really useful for instantly creating parent nulls without disrupting existing hierarchy.

  • Filip Vandueren

    January 27, 2022 at 12:47 pm

    This script should do it:

    app.beginUndoGroup("Group-Parent selected Layers");

    gAI = app.project.activeItem;

    gSL = gAI.selectedLayers;

    parentCandidates=[];

    is3D = false;

    // check which layers don't have a parent and store them in an array

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

    l = gSL[i];

    if (l.parent==null) {

    parentCandidates.push(gSL[i]);

    // if any layers is 3D, the Null will need to be 3D too.

    if (l.threeDLayer) {

    is3D = true;

    }

    }

    }

    // if there are any, create a Null.

    if (parentCandidates.length>0) {

    n = gAI.layers.addNull();

    n.threeDLayer = is3D;

    // calculate the average position of the layers

    avgPos=[0,0,0];

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

    l=parentCandidates[i];

    avgPos+=l.position.value;

    }

    avgPos/=parentCandidates.length;

    n.position.setValue(avgPos);

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

    l=parentCandidates[i];

    l.parent = n;

    }

    }

    app.endUndoGroup();

  • Laurie Gibbs

    January 27, 2022 at 1:51 pm

    Hi Filip,

    This is great! Thanks so much for making this. I have one question, is it possible for the null position to be the average of all the selected layers. It currently seems to create the average position of the unparented layers only.

    Thanks so much.

  • Filip Vandueren

    January 28, 2022 at 7:49 am

    Not as straightforward as one would think, because Scripts can’t directly see the absolute position of a child (there is no toComp() method in extendscript).

  • Laurie Gibbs

    January 28, 2022 at 10:36 am

    Ahh, I did wonder if that may be an issue. Never mind. Thanks v much for making this script. I do love it.

  • Laurie Gibbs

    February 16, 2022 at 4:27 pm

    Hi Filip.

    Thanks again for making this script. I am using it a lot in my workflow. I was wondering if it would be easy to create a version where you can select a group of layers, then run the script and it will leave just the un-parented layers selected?

    That would be ace.

    Best regards,

    Laurie

  • Filip Vandueren

    February 17, 2022 at 11:35 am

    Hi Laurie, this script should do just that:

    app.beginUndoGroup("Deselect parented layers of current selection");
    var sel = app.project.activeItem.selectedLayers;
    for (var i=sel.length; i>0; i--) {
    var sl = sel[i-1];
    if (sl.parent!==null) {
    sl.selected=false;
    };
    }
    app.endUndoGroup();
  • Laurie Gibbs

    February 17, 2022 at 1:28 pm

    You are amazing. Thank you very much!!

Viewing 1 - 8 of 8 posts

Log in to reply.

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