Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Script to find if mask's vertices are out of comp – Help Needed

  • Script to find if mask's vertices are out of comp – Help Needed

  • Tom Pinnes

    January 26, 2021 at 4:04 pm

    Hello everyone!

    I’m trying to write a script that checks for every solid layer in every frame if the mask goes out of the comp’s resolution. If it finds an instance it “snaps” it to the comp’s resolution and creates a keyframe there if there isn’t one already.

    Please assume –

    * Only 1 comp and only 1 mask per solid

    *This line of code isn’t working – myShape[0][0].setValue(widthDifference);

    * A mask will never be completely out of comp

    *All masks are rectangles

    //Start

    {

    var project = app.project;

    var currentComp = project.activeItem;

    var compWidth = currentComp.width;

    var compHeight =currentComp.height;

    var allLayers = currentComp.layers;

    var numOfLayers = allLayers.length;

    var frameRate = currentComp.frameRate;

    for(var i=1;i<=numOfLayers;i++)

    {

    var currentLayer = allLayers[i];

    var firstframeTime = currentLayer.inPoint*frameRate;

    var lastframeTime = currentLayer.outPoint*frameRate;

    if(currentLayer.source.mainSource instanceof SolidSource)

    {

    for(var k=firstframeTime;k<lastframetime;k++)< p=””></lastframetime;k++)<>

    {

    var widthDifference = currentLayer.width – compWidth;

    var heightDifference = currentLayer.height – compHeight;

    var maskPath = currentLayer.mask(1);

    var myMaskShape = maskPath.property(“maskShape”);

    var myShape = myMaskShape.value;

    var myVertices = myShape.vertices;

    if(myVertices[0][0]>widthDifference)

    {

    myShape[0][0].setValue(widthDifference);

    }

    if(myVertices[0][1]>heightDifference)

    {

    myShape[0][1].setValue(heightDifference);

    }

    if(myVertices[2][0]<widthdifference)< p=””></widthdifference)<>

    {

    myShape[2][0].setValue(widthDifference);

    }

    if(myVertices[2][1]<heightdifference)< p=””></heightdifference)<>

    {

    myShape[2][1].setValue(heightDifference);

    }

    }

    }

    }

    }

    //End

    I know this isn’t the prettiest code but i’d love some help and feedback to improve.

    Thanks in advance !

  • Tom Pinnes

    January 31, 2021 at 11:17 am

    Still in need of help, thanks 🙂

Viewing 1 - 2 of 2 posts

Log in to reply.

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