Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reversed order when using script to copy layers

  • Reversed order when using script to copy layers

    Posted by Ben Christie on April 10, 2024 at 6:05 am

    I have built a script where I am importing a comp, copying the layers from that comp and placing them into my currently selected comp. The function I’m using to transfer these layers is below. Everything works really well but I’m finding the layer order is completely reversed in thew new comp compared to the old. Any idea how to fix this?

    function copyLayersFromCompToComp(sourceComp, destinationComp) {
    var allSourceLayers = sourceComp.layers
    for (var sourceLayerIndex = 1; sourceLayerIndex <= allSourceLayers.length; sourceLayerIndex++) {
    var sourceLayer = allSourceLayers[sourceLayerIndex]
    sourceLayer.copyToComp(destinationComp)
    }
    }
    Brie Clayton
    replied 2 years, 1 month ago
    3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    April 10, 2024 at 6:51 am

    This should work:

    function copyLayersFromCompToComp(sourceComp, destinationComp) {
    var allSourceLayers = sourceComp.layers
    for (var sourceLayerIndex = sourceComp.numLayers; sourceLayerIndex > 0; sourceLayerIndex--) {
    var sourceLayer = sourceComp.layer(sourceLayerIndex);
    sourceLayer.copyToComp(destinationComp)
    }
    }
  • Ben Christie

    April 10, 2024 at 4:46 pm

    YES! That works perfectly. I have to say, I’ve been relying on your valuable advice and insight for YEARS Dan. Thanks so much as always.

  • Brie Clayton

    April 10, 2024 at 6:00 pm

    Thank you for solving this, Dan!

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