Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: HomeForumBasicsExpressionsTutorialsPodcastsMotion GraphicsTrainingCinema 4DFAQ

Re: Loading an expression with a script

Cow Forums : Adobe After Effects Expressions
VIEW POSTS   •   ADD A NEW POST   •   SEARCH   •   CHANGE FORUM
Respond to this post   •   Return to posts index   •   Read entire thread


Re: Loading an expression with a script
by Ben Frank on Nov 5, 2009 at 11:10:09 pm

thanks so much, dan! i finally got this working.

// create new comp named 'Bounce Variable Controls'
var compW = 720; // comp width
var compH = 540; // comp height
var compL = 1; // comp length (seconds)
var compRate = 29.97; // comp frame rate
var compBG = [0/255,0/255,0/255] // comp background color

var myItemCollection = app.project.items;
var controlComp = myItemCollection.addComp('Bounce Variable Controls',compW,compH,1,compL,compRate);
controlComp.bgColor = compBG;


// create new 50X50 yellow solid named 'Bounce Variable Controls'
mySolid = controlComp.layers.addSolid([255/255,255/255,0/255], "Bounce Variable Controls", 50, 50, 1);


// Add "Amplitude" Slider and set value to 10
Slider1 = mySolid.property("Effects").addProperty("Slider Control");
Slider1.name = "Amplitude";
controlComp.layer("Bounce Variable Controls")("Effects")("Amplitude")("Slider").setValue(10);

// Add "Frequency" Slider and set value to 40
Slider2 = mySolid.property("Effects").addProperty("Slider Control");
Slider2.name = "Frequency";
controlComp.layer("Bounce Variable Controls")("Effects")("Frequency")("Slider").setValue(40);

// Add "Decay" Slider and set value to 100
Slider3 = mySolid.property("Effects").addProperty("Slider Control");
Slider3.name = "Decay";
controlComp.layer("Bounce Variable Controls")("Effects")("Decay")("Slider").setValue(100);


// Add Expressions to Position, Rotation & Scale of All Layers in project
for (var i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i) instanceof CompItem && app.project.item(i).name != "Bounce Variable Controls") {
for (var j = 1; j <= app.project.item(i).numLayers; j++) {
app.project.item(i).layer(j).position.expression = "// Auto Easing with Retract for Positionn n = 0;n if (numKeys > 0){n n = nearestKey(time).index;n if (key(n).time > time){n n--;n }n }n if (n == 0){n t = 0;n }else{n t = time - key(n).time;n }n n if (n > 0){n v = velocityAtTime(key(n).time - thisComp.frameDuration/10);n amp = .01*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Amplitude")("Slider");n freq = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Frequency")("Slider");n decay = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Decay")("Slider");n value + v*amp*Math.sin(freq*t)/Math.exp(decay*t*2);n }else{n value;n }";

app.project.item(i).layer(j).rotation.expression = "// Auto Easing with Retract for Rotationn n = 0;n if (numKeys > 0){n n = nearestKey(time).index;n if (key(n).time > time){n n--;n }n }n if (n == 0){n t = 0;n }else{n t = time - key(n).time;n }n n if (n > 0){n v = velocityAtTime(key(n).time - thisComp.frameDuration/10);n amp = .005*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Amplitude")("Slider");n freq = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Frequency")("Slider");n decay = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Decay")("Slider");n value + v*amp*Math.sin(freq*t)/Math.exp(decay*t*2);n }else{n value;n }";

app.project.item(i).layer(j).scale.expression = "// Auto Easing with Retract for Scalen n = 0;n if (numKeys > 0){n n = nearestKey(time).index;n if (key(n).time > time){n n--;n }n }n if (n == 0){n t = 0;n }else{n t = time - key(n).time;n }n n if (n > 0){n v = velocityAtTime(key(n).time - thisComp.frameDuration/10);n amp = .05*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Amplitude")("Slider");n freq = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Frequency")("Slider");n decay = .1*comp("Bounce Variable Controls").layer("Bounce Variable Controls").effect("Decay")("Slider");n value + v*amp*Math.sin(freq*t)/Math.exp(decay*t*2);n }else{n value;n }";
}
}
}


ben

--
Check out my food blog: http://iAteThat.com
--
benfRank
art direction / broadcast, print & web design / photography
WEB: www.behance.net/benfrank/Frame
WEB: www.benfrankdesign.com
WEB: www.benfrankphotography.com


Respond to this post   •   Return to posts index   •   Read entire thread


Current Message Thread:


Related Tags:
DI



Note: If you are a registered user please click here to login before posting.

Your post will not be accepted if your name and email address are not registered in our database. Click here if you do not have an account.

Name
E-Mail Address
Subject
E-Mail me when someone responds
Just This Message   Entire Thread   None  

Message:



Note: The following are HTML characters and may cause parts of your post to disappear if not used correctly: < > &
To include any portion of the post in your response, highlight the desired text and hit the "Q" key. Read more...



Please post Expressions Code in the box below:


Add your message signature


 


Note: By clicking "Post Direct" button above, you are agreeing to the Creative Cow's Code of Conduct.



FORUMSTUTORIALSMAGAZINETRAININGVIDEOS - REELSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]