Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions scripting question

  • scripting question

    Posted by Ryan Rusnak on May 21, 2009 at 5:15 pm

    Hello,

    Please forgive my ignorance. What I am trying to do is: having two layers selected, upon the running of this script, both layers to move their anchor points to the edge of the layer on x and the middle of the layer on y while the lowest in the timeline changes position. I don’t care where it repositions to yet, just that it moves so I threw “width” and “height” in just for a test.

    From my understanding the following line of code should move the lowest of the selected layers to a new position.

    var myPosition = myComp.selectedLayers[1].property(“position”);
    myPosition.setValue([myWidth, myHeight]);

    and it does. but If I change the [1] to a [0] it makes no difference. It still moves the lowest layer. Can someone please explain to me why and how to fix this?

    My second concern is that when it does move, it moves to [0.0,0.0] rather than what I would expect which is [500,10] the layers height and width. The anchor point moves to [0,0] as well and I want it to move to [0,5]. Can anyone explain this to me?

    I started learning scripting yesterday so the answers may be really simple. Below is my whole script as it is right now. Thanks a lot, Ryan

    {
    app.beginUndoGroup(“snap”);
    var myComp = app.project.activeItem;

    for (i=0; i

    Ryan Rusnak replied 17 years ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 21, 2009 at 6:21 pm

    width and height are layer attributes, not properties. So you should do something like this:

    var myWidth = mySolid.width;
    var myHeight = mySolid.height/2;

    FYI – when you paste code into this forum, you’ll want to make sure you leave a space before and after your less-than and greater-than operators or a bunch of your code may get interpreted as html (like happend to your for loop). Or, you could use the entry panel provided for posting expressions, but that comes with its own set of challenges.

    Dan

  • Ryan Rusnak

    May 21, 2009 at 6:50 pm

    Thanks a lot Dan, for your help.

    Thanks, Ryan

  • Ryan Rusnak

    May 21, 2009 at 7:57 pm

    Ok, I have things working but I am now encountering a new challenge. I think that I need to convert comp space to to the layer space of a particular layer. Does any one know how to do that? I’ve searched and am still searching but have not found anything yet.

    In the code below, I want the value in the first dimension of the array to be the edge of the layer selectedLayers[0]. The number that I am getting now is correct but I think it is in comp space rather than layer space.

    myPositionTwo.setValue([myComp.selectedLayers[0].width, myHeight]);

    below is my updated code. Thanks a lot, Ryan

    {
    app.beginUndoGroup("snap");

    var myComp = app.project.activeItem;

    for (i = 0; i < 1; + + i ){

    if (myComp.selectedLayers.length < = 1 || myComp.selectedLayers.length > = 3){
    alert("please select two layers");
    }else{

    var mySolid = myComp.selectedLayers[i];
    var myWidth = mySolid.width;
    var myHeight = mySolid.height/2;
    var myAnchor = mySolid.property("anchorPoint");

    myAnchor.setValue([myWidth,myHeight]);

    var myPositionTwo = myComp.selectedLayers[1].property("position");
    var myPositionOne = myComp.selectedLayers[0].property("position");

    myPositionTwo.setValue([myComp.selectedLayers[0].width, myHeight]);
    }
    }
    app.endUndoGroup();
    }

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