Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions scripting: replaceSource for null layer

  • scripting: replaceSource for null layer

    Posted by Ross Klettke on April 25, 2016 at 9:22 pm

    Hi,
    I’m trying to write a simple script that will do batch source replacing — specifically to attach footage to C4D particles exported as AE nulls.

    An example project file (AE 2015) and script can be downoaded here: 10016_replacesourceofnull.zip
    The script is also posted below.
    (To use the script, first select the project item to be swapped in and then the null layer.)

    The problem: running replaceSource() on a null layer results in an “invisible” layer — the swap appears to be successful in the timeline view (and I make sure that the layer’s opacity is at 100%) but it is not visible in the Composition Viewer, though the layer’s bounds do appear to be updated.

    Replacing the null’s source manually (using opt+drag or the keyboard shortcut) works fine — and I’m confused why there’s a difference between that and replaceSource()

    Maybe I’m overlooking something obvious? Any Ideas?

    Thanks,
    –Ross

    *using AE 2015

    app.beginUndoGroup("Source Swap");

    app.activeViewer.setActive();
    var theSelectedLayers = app.project.activeItem.selectedLayers;
    var theSelectedItemsToSwapIn = app.project.selection;

    if(theSelectedLayers.length > 0 && theSelectedItemsToSwapIn.length > 0){
    for(var i = 0; i < theSelectedLayers.length; i++){
    var j = i % theSelectedItemsToSwapIn.length;
    theSelectedLayers[i].replaceSource(theSelectedItemsToSwapIn[j], true);
    }
    } else {
    alert("Error: Please select 1 or more layers and 1 or more items in the Project window");
    }

    app.endUndoGroup();

    Ross Klettke replied 10 years ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

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