Control layer position from another layer

Scripting for After Effects

Control layer position from another layer

Postby ha2_ on 08/29/2015, 9:56 am

Hi,

I want make expression preset that I just aply on layers many times in future.
I need 1 control Layer and two other layers.
layers.jpg


So, i want add 4 controls to CONTROL layer.
slider for position X, slider for position Y and 2x Layer control.

My idea is to have this as preset so in future I just paste this preset to some layer that I want to be control layer and chose another 2 layers.
After that these 2 layers, first jump to left and second jump to top position like on image above and I can control position of those three layers with sliders from CONTROL layer. So these 2 layers are pinned to control layer.

I can make this manually but I want to have preset for this action because I need do this many times.
Is it possible do it?

Thx
ha2_
 
Posts: 14
Joined: 04/14/2013, 4:06 am

Re: Control layer position from another layer

Postby plae57 on 08/29/2015, 12:04 pm

Go go lesterbanks.com and scroll through the recent articles. There is one that has 25 after effects tips you didn't know about. One of the 25 tips is how to control something in one comp and something else in a different comp.
plae57
 
Posts: 574
Joined: 08/4/2014, 4:12 am

Re: Control layer position from another layer

Postby ha2_ on 08/29/2015, 2:00 pm

I know how do it manually, but I don't want make this 150x and I dont want to every time make expressions from every one of these 3 layers for positions and linked it to control layers ... I want make preset that make everything automatically I just put it to control layer and that's it.
ha2_
 
Posts: 14
Joined: 04/14/2013, 4:06 am

Re: Control layer position from another layer

Postby plae57 on 08/29/2015, 8:33 pm

ha2_ wrote:I know how do it manually, but I don't want make this 150x and I dont want to every time make expressions from every one of these 3 layers for positions and linked it to control layers ... I want make preset that make everything automatically I just put it to control layer and that's it.


The expression you create is exactly the same as the script you would write in a preset. If you go here: http://www.adobe.com/devnet/aftereffects.html You will find examples of the other code you night need. Anyway, you may need to download the script editor. after downloading it you can find it in the file menu of after effects. Open it and pretty much cut and paste the code created with the pick whip to do the same thing.

Save this file and use it over and over. Here is example of code I wrote to create a simple camera rig here: viewtopic.php?f=5&t=123769 This might give you some examples of code tou can use. The section called Position Expression show you how to add an expression via a script.

Good luck, scripting is not that hard if you know some basic java-script or C++.
plae57
 
Posts: 574
Joined: 08/4/2014, 4:12 am

Re: Control layer position from another layer

Postby ha2_ on 08/30/2015, 3:55 am

Thx! this helped.

now i have this code
Code: Select all
// create new comp

  var compW = 1920; // comp width
  var compH = 1080; // comp height
  var compL = 10;  // comp length (seconds)
  var compRate = 25; // comp frame rate
  var compBG = [48/255,63/255,84/255] // comp background color
  var myItemCollection = app.project.items;
  var ThisComp = myItemCollection.addComp('my comp',compW,compH,1,compL,compRate);
  ThisComp.bgColor = compBG;


//create solid
var mySolid2 = ThisComp.layers.addSolid([1.0,1.0,0], "Left", 1920, 1080, 1);
var mySolid3 = ThisComp.layers.addSolid([1.0,1.0,0], "Top", 1920, 1080, 1);
var mySolid = ThisComp.layers.addSolid([1.0,1.0,0], "Control", 1920, 1080, 1);
mySolid2.position.setValue([-960,540]);
mySolid3.position.setValue([960,-540]);

// Add controlers
var Xslider = mySolid.Effects.addProperty("ADBE Slider Control");
Xslider.name="X Position";
Xslider.Slider.setValue(w);
var Yslider = mySolid.Effects.addProperty("ADBE Slider Control");
Yslider.name="Y Position";
Yslider.Slider.setValue(h);


// parent the position to controlers
// Position Expression
var PositionExpression = "[thisComp.layer(\"Control\").effect(\"X Position\")(\"Slider\"),thisComp.layer(\"Control\").effect(\"Y Position\")(\"Slider\")]";
mySolid.property("position").expression = PositionExpression;

var PositionExpression = "temp = thisComp.layer(\"Control\").transform.position[0];temp2 = thisComp.layer(\"Control\").transform.position[1];[temp, temp2-1080]";
mySolid2.property("position").expression = PositionExpression;

var PositionExpression = "temp = thisComp.layer(\"Control\").transform.position[0];temp2 = thisComp.layer(\"Control\").transform.position[1];[temp-1920, temp2]";
mySolid3.property("position").expression = PositionExpression;


let's say I want this 2 layers (Left and Top) precomposed and that expresions have on compositions, just for better source change.
How I precompose it or, how make composition iside this "my comp" composition and aply there this stuf above?
ha2_
 
Posts: 14
Joined: 04/14/2013, 4:06 am


Return to After Effects Expressions