Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Anchor point positioning

Tagged: 

  • Anchor point positioning

    Posted by Stanley Castello on April 13, 2022 at 12:12 pm

    Hi all!

    I am new on scripting so if you could help me I will appreciate it greatly.

    I have this function: It places two scale keyframes I need. My question is, how can I change the anchor point to middle/left before the scale keyframe is applied? I tried all kind of ways but nothing has worked 🙁

     

    function scaleUpLeft(){

    var comp = app.project.activeItem;

    if(comp === null){

    alert(‘Please open a comp’)

    return

    };

    var keyTime = comp.time;

    var addTime = keyTime + 1.25;

    var myLayer = comp.selectedLayers;

     

    app.beginUndoGroup(“Scale up”);

     

    for(var i = 0; i < myLayer.length; i++){

    myLayer[i].property(“Transform”).property(“Scale”).setValueAtTime(keyTime,[0,100]);

    myLayer[i].property(“Transform”).property(“Scale”).setValueAtTime(addTime,[100,100]);

    };

    };

    app.endUndoGroup();

    Stanley Castello replied 4 years, 4 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    April 13, 2022 at 4:23 pm

    Something like this inside your loop, I think:

    var r = myLayer[i].sourceRectAtTime(0,true);

    var delta = [r.left, r.top + r.height/2];

    var ap = myLayer[i].property("Anchor Point").value;

    var pos = myLayer[i].property("Position").value;

    myLayer[i].property("Anchor Point").setValue([ap[0] + delta[0], ap[1] + delta[1]]);

    myLayer[i].property("Position").setValue([pos[0] + delta[0], pos[1] + delta[1]]);

  • Stanley Castello

    April 13, 2022 at 5:32 pm

    Something is telling me; you are a complete genius. That worked really well. Thank you very much.

  • Stanley Castello

    April 13, 2022 at 6:11 pm

    One more question, if I wanted the anchor point to be placed on top/middle would I just change the;

    var delta = [r.left, r.top + r.height/2]; <<–?

  • Dan Ebberts

    April 13, 2022 at 7:27 pm

    Yes:

    var delta = [r.left + r.width/2, r.top];
  • Dan Ebberts

    April 13, 2022 at 7:45 pm

    Oops, those are messed up. The first one should be:

    var r = myLayer[i].sourceRectAtTime(0,true);

    var ap = myLayer[i].property("Anchor Point").value;

    var delta = [r.left - ap[0] , r.top + r.height/2 - ap[1]];

    var pos = myLayer[i].property("Position").value;

    myLayer[i].property("Anchor Point").setValue([ap[0] + delta[0], ap[1] + delta[1]]);

    myLayer[i].property("Position").setValue([pos[0] + delta[0], pos[1] + delta[1]]);

    and the second one should be:

    var r = myLayer[i].sourceRectAtTime(0,true);

    var ap = myLayer[i].property("Anchor Point").value;

    var delta = [r.left + r.width/2 - ap[0] , r.top - ap[1]];

    var pos = myLayer[i].property("Position").value;

    myLayer[i].property("Anchor Point").setValue([ap[0] + delta[0], ap[1] + delta[1]]);

    myLayer[i].property("Position").setValue([pos[0] + delta[0], pos[1] + delta[1]]);

  • Stanley Castello

    April 14, 2022 at 1:01 am

    Works wonderfully! Thank you so much.

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