Skip to main content
Inspiring
March 8, 2025
Answered

How do I modify this script to set the Mask mode to SUBTRACT, instead of the default ADD?

  • March 8, 2025
  • 1 reply
  • 344 views

I have this script which attempts to create a vignette. However, the Mask mode is set to Add so it is currently a reverse Vignette (ie a soft black ellipse). How to I modify this script to make it Subtract instead? Or if that is not possible, Add Invert?

 

 

app.beginUndoGroup("Create Vignette");

var comp = app.project.activeItem;
if (comp && comp instanceof CompItem) {
    var layer = comp.selectedLayers[0];

    if (!layer) {
        // Create a black solid if no layer is selected
        layer = comp.layers.addSolid([0, 0, 0], "Black Solid", comp.width, comp.height, comp.pixelAspect);
    }

    if (layer) {
        var mask = layer.Masks.addProperty("Mask");
        var maskShape = mask.property("maskShape").value;
        
        var compWidth = comp.width;
        var compHeight = comp.height;
        
        maskShape.vertices = [
            [compWidth * 0.5, 0],
            [compWidth, compHeight * 0.5],
            [compWidth * 0.5, compHeight],
            [0, compHeight * 0.5]
        ];
        
        maskShape.inTangents = [
            [-compWidth * 0.25, 0],
            [0, -compHeight * 0.25],
            [compWidth * 0.25, 0],
            [0, compHeight * 0.25]
        ];
        
        maskShape.outTangents = [
            [compWidth * 0.25, 0],
            [0, compHeight * 0.25],
            [-compWidth * 0.25, 0],
            [0, -compHeight * 0.25]
        ];
        
        mask.property("maskShape").setValue(maskShape);
        mask.property("maskFeather").setValue([750, 750]);
    }
} else {
    alert("Please open a composition first.");
}

app.endUndoGroup();

 

 

 

 

 

Correct answer Dan Ebberts

Add this:

mask.maskMode = MaskMode.SUBTRACT;

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 8, 2025

Add this:

mask.maskMode = MaskMode.SUBTRACT;

 

Inspiring
March 8, 2025

Wonderful. Thank you!