Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Acces X and Y values of vertices seperately ?

  • Acces X and Y values of vertices seperately ?

    Posted by Steve Sierra on May 1, 2017 at 5:55 am

    Hi,

    For a script I am working on, I want to duplicate and reduce my mask shape multiple times.
    So I need to know where my Mask shape vertices are compared to my Layer’s half width and height (if the verts are in the top/left, top/right, bottom left or bottom right quarters of myLayer) in order to push them in.

    To do that, I would need to compare the x value of each vertice with the layer’s half width and it’s Y value with the layer’s half height in a for loop…

    Could anyone tell me how to do this ?

    Thanks in advance !
    😉

    Steve Sierra replied 9 years ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 1, 2017 at 6:12 am

    If you know the coordinates of the center, you should be able to figure out which quadrant a given vertex (v) is in with something like this:


    center = ???
    if (v[0] < center[0]){
    if (v[1] < center[1]){
    // upper left
    }else{
    // lower left
    }
    }else{
    if (v[1] < center[1]){
    // upper right
    }else{
    // lower right
    }
    }

    Dan

  • Steve Sierra

    May 1, 2017 at 9:58 am

    Hi Dan,

    Thanks for your quick reply !
    That’s exactly what I am trying to do… The problem is, isn’t v[0] the first vertex of the shape, v[1] the second, etc…
    I don’t know how to get to “v[0].value[0]” or “v[0].value[1]”.

    Here’s what I’m doing :

    var origLayer = app.project.activeItem.selectedLayer[0];
    var origHalfX = origLayer.width/2;
    var origHalfY = origLayer.height/2;
    var origShape = origLayer.property(“ADBE Mask Parade”).property(“ADBE Mask Atom”).property(“ADBE Mask Shape”).value;
    var origVerts = origShape.vertices;

    for(var i = 0; i< numZLayers; i++){

    var copyLayer = origLayer.duplicate();
    var copyShape = copyLayer.property(“ADBE Mask Parade”).property(“ADBE Mask Atom”).property(“ADBE Mask Shape”).value

    var modifiedShape = origShape;
    var modifiedVerts = modifiedShape.vertices;
    var h = origHalfX * (i/numZLayers);
    var v = origHalfY * (i/numZLayers);

    for(var j = 0; j < origVerts.length; j++){
    var Overt = origVerts[j];
    var Mvert = modifiedVerts[j];
    var OvertX = Overt[0];
    var OvertY = Overt[1];

    if(OvertX < origHalfX && OvertY < origHalfY){origVertsM[j] = [OvertX + h, OvertY + v]};
    if(OvertX < origHalfX && OvertY > origHalfY){origVertsM[j] = [OvertX + h, OvertY – v]};
    if(OvertX > origHalfX && OvertY < origHalfY){origVertsM[j] = [OvertX – h, OvertY + v]};
    if(OvertX > origHalfX && OvertY > origHalfY){origVertsM[j] = [OvertX – h, OvertY – v]};
    }
    copyShape = modifiedShape;

    Thanks !;)

  • Steve Sierra

    May 2, 2017 at 7:42 am

    Hi,

    I think I found what I was doing wrong thanks to this page:

    https://omino.com/pixelblog/2008/12/25/ae-mask-vertices-from-extendscript/

    before the last line, I had to re-inject the vertices in the shape, and then set the value of the shape, not with “=”.
    So the ending should have been :

    modifiedShape.vertices = origVertsM;
    copyShape.setValue(modifiedShape);

    Cheers !

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