Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using Script to turn a mask on or off in After Effects

New Here ,
May 21, 2018 May 21, 2018

I am looking for a way to turn the mask on this blue solid from “Add” to “None” using script. The closest script I could find that does this is here:

var myComp = app.project.activeItem;

var greenSolid = myComp.layers.addSolid([0,1.0,0], "Green Solid", 50, 50, 1);

var newMask = greenSolid.Masks.addProperty("Mask");

var myMaskShape = newMask.property("maskShape");

var myShape = myMaskShape.value;

myShape.vertices = [[10,10],[10,40],[40,40],[40,10]];

myShape.closed = true;

newMask.maskMode = MaskMode.NONE; // note the lower case "m" in ".maskMode"

newMask.maskExpansion.setValue(7.5);

myMaskShape.setValue(myShape);

This script creates a green square and then puts a mask around it that you can change the property of in the line “newMask.maskMode = MaskMode.NONE;”

I just need to be able to refer to the mask on the solid instead of create it like in the script above. Does anyone know how I would write that out?

Screen Shot 2018-05-21 at 1.53.48 PM.png

TOPICS
Scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , May 22, 2018 May 22, 2018

In that case simply pass your layers array and you should be golden.

forEachLayerDo(layersArray, setMaskMode);

function forEachLayerDo(layers, callback) {

    var layer;

    for (var i = 0, il = layers.length; i < il; i++) {

        layer = layers;

        callback(layer);

    }

}

function setMaskMode(layer) {

    var maskParade = layer.property('ADBE Mask Parade');

    var maskProperty;

    for (var m = 1, ml = maskParade.numProperties; m <= ml; m++) {

        maskProperty = maskParade.property(m);

        m

...
Translate
Advocate ,
May 22, 2018 May 22, 2018

rd_GimmePropPath script is indispensable in this scenario http://www.redefinery.com/ae/view.php?item=rd_GimmePropPath

In case you have only one composition with one layer in it with one mask - this snippet will work:

var maskProperty = app.project.item(1).layer("White Solid 1").property("ADBE Mask Parade").property("ADBE Mask Atom");

maskProperty.maskMode = MaskMode.NONE;

If you want to push this functionality further, to say set mask mode to all selected layers, here's a snippet:

(function() {

    var composition = app.project.activeItem;

    if (!composition || !(composition instanceof CompItem)) {

        return alert("Please select composition first");

    }

    var selectedLayers = composition.selectedLayers;

    app.beginUndoGroup("undoString");

    forEachLayerDo(selectedLayers, setMaskMode);

    app.endUndoGroup();

    function forEachLayerDo(layers, callback) {

        for (var i = 0, il = layers.length; i < il; i++) {

            layer = layers;

            callback(layer);

        }

    }

    function setMaskMode(layer) {

        var maskParade = layer.property('ADBE Mask Parade');

        var maskProperty;

        for (var m = 1, ml = maskParade.numProperties; m <= ml; m++) {

            maskProperty = maskParade.property(m);

            maskProperty.maskMode = MaskMode.NONE;

        }

    }

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2018 May 22, 2018

Hey, that worked! In the second script, the one that works for all selected layers, is there a way to change it so that they don't necessarily have to be selected for it to work? Like if I were able to put the layers that needed to change into an array? My goal is to be able to run this script after the project is completed without having to search through everything manually.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 22, 2018 May 22, 2018

In that case simply pass your layers array and you should be golden.

forEachLayerDo(layersArray, setMaskMode);

function forEachLayerDo(layers, callback) {

    var layer;

    for (var i = 0, il = layers.length; i < il; i++) {

        layer = layers;

        callback(layer);

    }

}

function setMaskMode(layer) {

    var maskParade = layer.property('ADBE Mask Parade');

    var maskProperty;

    for (var m = 1, ml = maskParade.numProperties; m <= ml; m++) {

        maskProperty = maskParade.property(m);

        maskProperty.maskMode = MaskMode.NONE;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2018 May 22, 2018

I am having to hardest time figuring this out. I attached a screenshot of my project items and everything in my timeline. I am just trying to grab those four precomps in the middle and put them into an array but it keeps throwing me "undefined". Do you know how I could write it so that I put those 4 into an array to run through the rest of the script? (I am very new to this scripting thing if you can't tell and I appreciate all the help!)

Screen Shot 2018-05-22 at 4.06.07 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 22, 2018 May 22, 2018

Can you please share your code you've got so far?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 23, 2018 May 23, 2018

You should really share your code if you want to learn something. Otherwise I can just do wild assumptions of your setup.

Never the less, to answer your last question:

// Assuming 'myComposition' is active composition

// that holds 4 layers (indices 3-6) with masks in it

var layersArray = [];

layersArray.push(myComposition.layer(3));

layersArray.push(myComposition.layer(4));

layersArray.push(myComposition.layer(5));

layersArray.push(myComposition.layer(6));

forEachLayerDo(layersArray, setMaskMode);

< ... >

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2018 May 23, 2018
LATEST

Sweet that worked! Sorry I didn't get back to you sooner. The way I was trying to do it was by defining each layer I wanted to put into the array as a variable like this:

app.project.item(1).layer(3)

I think the first place I went wrong was trying to define the item as the layer I was trying to grab, so when I was trying to grab account center for example I was pointing to account center in the library as the item instead of the active comp which is why it kept coming up as undefined I would guess. And honestly all the code after that was a huge mess.

Thank you so much for your help on this, I really appreciate it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines