Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Transform Position Script

  • Transform Position Script

    Posted by Jess Wellington on June 5, 2014 at 5:21 pm

    I am new to scripting, but I am trying to learn. I am trying to write a script that is currently done with keyframes and has become quite repetitive. I would like the script to take the selected layer and move it a specific amount in the x, y and z directions. Something similar to this expression, but in script form.

    x = transform.position[0];
    y = transform.position[1];

    [(x+315), (y-200)]

    Maria Pixamins replied 2 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Jess Wellington

    June 5, 2014 at 5:38 pm

    Or similar to this expression.

    transform.position + [315,-200];

  • Dan Ebberts

    June 5, 2014 at 6:02 pm

    Something like this (assuming the target layer is the first layer and has no keyframes):

    var myLayer = app.project.activeItem.layer(1);
    var curVal = myLayer.property(“Position”).value;
    myLayer.property(“Position”).setValue([curVal[0]+315,curVal[1]-200])

    Dan

  • Jess Wellington

    June 5, 2014 at 6:22 pm

    Thanks Dan! How would I change the script to accommodate keyframes and only affect the selected layer.
    Would I use:

    setValueAtKey
    selectedLayers

  • Dan Ebberts

    June 5, 2014 at 7:02 pm

    More like this:


    var mySelectedLayers = app.project.activeItem.selectedLayers;
    if (mySelectedLayers.length > 0){
    var myLayer = app.project.activeItem.selectedLayers[0];
    var myProp = myLayer.property("Position");
    var curVal;
    if (myProp.numKeys > 0){
    for (var i = 1; i <= myProp.numKeys; i++){ curVal = myProp.keyValue(i); myProp.setValueAtKey(i,[curVal[0]+300,curVal[1]-200]); } }else{ curVal = myProp.value; myProp.setValue([curVal[0]+300,curVal[1]-200]); } }

    Dan

    Edit: Oops, there was a typo in there

  • Maria Pixamins

    September 29, 2023 at 2:02 pm

    CooL

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