Reference a variable in an expression

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
thebunk
Posts: 2
Joined: December 5th, 2013, 9:51 am

I'm writing a script that will create a null with slider controls on it, and will automatically link to a selected layers position property. It will then create a wiggle expression. So essentially, the wiggle controls will be on a separate null, instead of the original layer.

It worked great until I decided to name the null according to the selected layer name, in case you do it for multiple layers. So if my layer is called "Red Box", the null is now called "Red Box Wiggle Control". That part works fine, but my wiggle expressions are broken. I'm not sure how to implement the variable of the layer name into an expression.

For example:

var myLayer = myComp.selectedLayers{0};
var myLayerName = myLayer.name;

var wiggleX = "wiggle(thisComp.layer((myLayerName)+(\" Wiggle Control\")).effect(\"X Frequency\")(\"Slider\"),thisComp.layer((myLayerName)+(\" Wiggle Control\")).effect(\"X Amount\")(\"Slider\"))";

After Effects looks for a layer called "myLayerName". Is there a way to implement the myLayerName variable into the expression?

Thanks for any help.
Rob
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

Yeah, just brake the expression string with quotation marks.

Code: Select all

var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
var myLayerName = myLayer.name;
var myNull = myComp.layers.addNull(myComp.duration);
myNull.name = myLayerName + " Wiggle Control";
var SliderXFrequency = myNull.Effects.addProperty("ADBE Slider Control");
SliderXFrequency.name = "XFrequency";
var SliderXAmount = myNull.Effects.addProperty("ADBE Slider Control");
SliderXAmount.name = "XAmount";

var wiggleX = "wiggle(thisComp.layer(\"" + myNull.name + "\").effect(\"XFrequency\")(\"Slider\"),thisComp.layer(\"" + myNull.name + "\").effect(\"XAmount\")(\"Slider\"));";

myLayer.property("Transform").property("Position").dimensionsSeparated = true;
myLayer.property("Transform").property("X Position").expression = wiggleX;
thebunk
Posts: 2
Joined: December 5th, 2013, 9:51 am

Thank you, this worked perfectly!
Post Reply