Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Mask Index linked to Layer index

  • Mask Index linked to Layer index

    Posted by Criis Daw on November 26, 2015 at 10:38 am

    Can anyone help me.. I am digging myself into a hole trying to solve a problem that might not even exist.

    I have a a psd layer with with lots of individual elements, some of which I would like to isolate and animate on different layers in 3d space.
    Rather than cut out each layer in photoshop and import a layered file I have been trying to take a short cut (which obviously has become a long cut .. but hey is the journey not the destination) and do it in after effects.

    My rational is to draw a mask around each element that i wish to isolate on one layer.
    I then want to add an expression that says
    if the index number of this mask equals the index number of this layer then set the mask opacity to 100% else 0%

    this should then allow me to draw masks on one layer then simply duplicate the layer (potentially 50+ times) and each layer will only have one transparent (on) mask and display only one element.

    i have been trying to use: thisProperty.propertyGroup(1).propertyIndex

    but i dont really know what i am doing or even if its a particularly efficient work flow. but any help will be greatly appreciated.

    Cheers

    Criis Daw replied 10 years, 5 months ago 2 Members · 13 Replies
  • 13 Replies
  • Martin Jean-sébastien

    November 26, 2015 at 1:36 pm

    Hello,
    You have to select all the layers where you want to apply this script :

    app.beginUndoGroup(“Set opacity mask”);

    for(var j=0;j

  • Martin Jean-sébastien

    November 26, 2015 at 1:37 pm

    Unknown issue of copy/paste here, type this :

    app.beginUndoGroup(“Set opacity mask”);

    for(var j=0;j

  • Martin Jean-sébastien

    November 26, 2015 at 1:38 pm

    Oh i try this

    app.beginUndoGroup("Set opacity mask");

    for(var j=0;j<app.project.activeItem.selectedLayers.length;j++){
    var myLayer = app.project.activeItem.selectedLayers[j];
    var myPath = myLayer.property("Masks");
    var numMasks = myPath.numProperties;
    for(var i=1;i<numMasks+1;i++){
    if(myPath.property(i).name.replace(/Mask /g, "")==myLayer.index) myPath.property(i).maskOpacity.setValue(100);
    else myPath.property(i).maskOpacity.setValue(0);
    }
    }

    app.endUndoGroup();

  • Criis Daw

    November 26, 2015 at 1:39 pm

    thanks..

    thats way more complicated than I imagined !

  • Criis Daw

    November 26, 2015 at 1:43 pm

    worked a treat .

    thanks..

  • Criis Daw

    November 26, 2015 at 1:53 pm

    now i am in really uncharted waters here but could a script be used to delete masks instead of turning the opacity to zero ?

    this would be an ideal work flow but it never crossed my mind as I was approaching it from an expression point of view …

  • Martin Jean-sébastien

    November 26, 2015 at 2:03 pm

    Here it is

    app.beginUndoGroup("Delete mask");

    for(var j=0;j<app.project.activeItem.selectedLayers.length;j++){
    var myLayer = app.project.activeItem.selectedLayers[j];
    var myPath = myLayer.property("Masks");
    var numMasks = myPath.numProperties;
    for(var i=1;i<numMasks+1;i++){
    if(myPath.property(i).name.replace(/Mask /g, "")==myLayer.index){
    myPath.property(i).remove();
    numMasks = numMasks-1;
    }
    else myPath.property(i).maskOpacity.setValue(0);
    }
    }

    app.endUndoGroup();

  • Criis Daw

    November 26, 2015 at 2:07 pm

    thanks thats brilliant..

    except it works the wrong way around. It keeps the ones I want to delete and deletes the one I want to keep…

  • Martin Jean-sébastien

    November 26, 2015 at 2:11 pm

    app.beginUndoGroup("Delete mask");

    for(var j=0;j<app.project.activeItem.selectedLayers.length;j++){
    var myLayer = app.project.activeItem.selectedLayers[j];
    var myPath = myLayer.property("Masks");
    var numMasks = myPath.numProperties;
    for(var i=1;i<numMasks+1;i++){
    if(myPath.property(i).name.replace(/Mask /g, "")==myLayer.index){
    myPath.property(i).maskOpacity.setValue(0);
    }
    else{
    myPath.property(i).remove();
    numMasks = numMasks-1;
    }
    }
    }

    app.endUndoGroup();

  • Criis Daw

    November 26, 2015 at 2:19 pm

    appreciate your efforts here but that’s still not doing it.

    each layer have 50 identical masks . Turning off the opacity of the 49 i didnt want to see worked fine but deleting them hasnt worked.

    this time it deleted mask 2 on layer 1 and left the rest . On the other layers all the masks see the same as before..

Page 1 of 2

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