Skip to content

Add 'aeq.project.getLayersDeep' method? #37

Description

@runegan

Original report by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


We have aeq.getItemsDeep to create a flat arrayEx of nested items in a folder. Having this for layers in a comp (and precomps) would be good.

Pass in a comp, get a flat arrayEx of all layers in the comp and precomps.

/**
 * Returns an arrayEx of all layers in comp and precomps

 * @param  {CompItem} comp   The comp to flatten.
 * @return {aeq.arrayEx}     ArrayEx with Layer objects.
 */
function getLayersDeep (comp, returnArrayEx) {
    // The returnArrayEx param is so we can skip the converting to arrayEx when
    // recursing. It is not meant to be used outside of this function.
    var layers = [];

    aeq.forEachLayer(comp, function (layer) {
        if (aeq.isPrecomp(layer))
            layers.push.apply(layers, getLayersDeep(layer.source, false));
        else
            layers.push(layer);
    });

    // Skip converting to arrayEx when function is called by it self.
    if (returnArrayEx === false)
        return layers;

    return aeq.arrayEx(layers);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions