Referencing Layers within Precomps

What type of scripts do you need?

Moderator: byronnash

Post Reply
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

Hi,

I'm using this expression on the scale of some precomps based on the closeness of another layer. But I also need it to change the opacity of a layer inside the precomps. All the precomps are set up the same way, with same amount of layers in the same order. What is the best way to go about referencing the layer? It would be best if I could do it by layer number.


startS = 200; //start scale 400 pixels from null
endS = 50; //end scale 50 pixels from null
C = thisComp.layer("Proximity").toWorld([0,0,0]);
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startS,endS,[125,125],[100,100])


Thanks in advance!
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

This should work for opacity. I also changed it so that it references the layer by layer number.

-Lloyd

Code: Select all

startS = 200; //start distance (in pixels) from null
endS = 50; //end distance from null
startO= 20; //starting opacity
endO= 100; //ending opacity
C = thisComp.layer(1).toWorld([0,0,0]);
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startS,endS,startO,endO)
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

Thanks, this actually works backwards from the way I thought it would (I was thinking apply it to the , but makes more sense this way too. Here's the final script I'm using:

startD = 200; //start distance (in pixels) from null
endD = 50; //end distance from null
startO= 100; //starting opacity
endO= 50; //ending opacity
C = comp("Comp Name").layer("Layer Name").toWorld([0,0,0]); //proximity layer
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startD,endD,startO,endO)

I had another question, what if I wanted to "ease" the movement, (like for the scale property) so that the movement isn't so linear? Is there a way to move the scale along a sine curve or something?
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

you can replace the word linear with ease to ease both your in and out like this:

Code: Select all

startS = 200; //start scale 400 pixels from null
endS = 50; //end scale 50 pixels from null
C = thisComp.layer("Proximity").toWorld([0,0,0]);
P = toWorld(anchorPoint);
d = length(C,P);
ease(d,startS,endS,[125,125],[100,100])
If you only want to ease the In, then use easeIn or easeOut for the out..

-Lloyd
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

Awesome, thanks for all the help!
Post Reply