Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Problem with changing a layers position in a script

  • Problem with changing a layers position in a script

    Posted by Coby Gross on May 22, 2013 at 5:47 am

    So I have a script that needs to change the position of a layer but I keep getting this error: invalid numeric result(divide by zero?)

    here is the line:
    myComp.layer(2).transform.position + [5,2]

    Any ideas as to why I would get this?
    Here is my While loop, also, the layer is a precomp if that makes a difference(I didnt think it would though)


    var myComp;
    //Read lins of text. Create a new comp and text layer for each line
    var text;

    while(!myFile.eof)
    {
    text = myFile.readln();
    if(text == "") text = "r";

    myComp = app.project.items.addComp(text,compW,compH,1,compL,compRate);

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Set the text layer
    var tl = myComp.layers.addText(text);
    var tltxt = tl.property("ADBE Text Properties").property("ADBE Text Document");
    var txt = tltxt.value;
    txt.font = "Verdana";
    tltxt.setValue(txt);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var precomp = myComp.layers;

    precomp.precompose([1],text + "precomp");
    myComp.layer(1).duplicate();
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Add Fill Effect
    layerProperties = myComp.layer(2);
    layerProperties.Effects.addProperty("Fill");
    layerProperties.Effects.property("Fill").property("Color").setValue([0,0,0]);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Add the offset

    //layerProperties.transform.position + [5,2];
    myComp.layer(1).transform.position + [5,2];

    }

    Jan Vork replied 8 years, 1 month ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 22, 2013 at 6:02 am

    If you’re trying to move the position of layer(1), I think you would need something more like this:

    var myVal = myComp.layer(1).property(“Position”).value;
    myComp.layer(1).property(“Position”).setValue(myVal+ [5,2]);

    Dan

  • Coby Gross

    May 22, 2013 at 6:57 am

    Yes, that did it. Thank you so much. Nearly every example I saw online had it something like myComp.layer(1).transform.position + [5,2]; So frustrating ha.

    Thank you again, you rock.

  • Jan Vork

    April 12, 2018 at 12:14 pm

    Thanks to you and Dan, I found that this works as well:

    myComp.layer(1).transform.position.setValue([5,2]);

    Looks a bit less complicated to me.

    Best,
    Jan

    myComp.layer(1).transform.position.setValue([5,2]);

    http://www.jaydude.nl

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