ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Problem with changing a layers position in a script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Coby Gross
Problem with changing a layers position in a script
on May 22, 2013 at 5:47:00 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];


}


Return to posts index

Dan Ebberts
Re: Problem with changing a layers position in a script
on May 22, 2013 at 6:02:25 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



Return to posts index

Coby Gross
Re: Problem with changing a layers position in a script
on May 22, 2013 at 6:57:27 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.


Return to posts index


Jan Vork
Re: Problem with changing a layers position in a script
on Apr 12, 2018 at 12:14:36 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]