ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Button that inputs expression from UI Panel

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Button that inputs expression from UI Panel
on Mar 15, 2017 at 9:59:51 pm

I can't think of any other way to word the subject.

I have scoured everywhere and cannot find what I am looking for as bizarre as it sounds. I have found threads where people want to create a script to add an expression, some who want an expression to add to multiple layers at once.

I have created a UI Panel with a button (Well a few buttons and dropdownlists), when I select my layer and click the button it will place the expression onto that property.

So for example.

myBtn: Panel{text:'Station Selector', orientation:'row', alignChildren:['left', 'fill'],\
Wiggle: Button{text:'Wiggle'},\


I have my button, if I assign it to change text etc

myPanel.grp.myBtn.Wiggle.onClick = function(){
var myComp = app.project.activeItem;
myComp.layer("[Station]").property("ADBE Text Properties").property("ADBE Text Document").setValue("Wiggle");


This works fine.

What I would like it to do is something on the lines of based off what I've seen and guessing at.

myPanel.grp.myBtn.Wiggle.onClick = function(){
var myComp = app.project.activeItem;
myComp.selectedLayers.property.expression = '[wiggle (2,10)]';


I'm using wiggle as a simpler expression, as I want to use more beefy expression, but essentially I want the button to add the expression to property I've selected. I want to set up something where I don't have to keep copying and pasting the expression. So I want a button that will just put it in.

Any help would be greatly appreciated


Return to posts index

Dan Ebberts
Re: Button that inputs expression from UI Panel
on Mar 16, 2017 at 12:49:13 am

Your function might look like this:


var myComp = app.project.activeItem;
var myExpression = 'wiggle (2,10)';
var myProps = myComp.selectedProperties;
for (var i = 0; i < myProps.length; i++){
if (myProps[i].canSetExpression){
myProps[i].expression = myExpression;
}
}



Dan



Return to posts index

Scott McGee
Re: Button that inputs expression from UI Panel
on Mar 16, 2017 at 9:03:30 am
Last Edited By Scott McGee on Mar 16, 2017 at 8:04:57 pm

Thank you very much Dan.

hahaha, I didn't see this and literally found something similar you wrote for someone else

var myEffect = myLayer.Effect.addProperty("ADBE Slider Control");
var myExpr = "amp = effect(1)("Slider");" + "r" +
"freq = effect(2)("Slider");" + "r" +
"x = ... etc. ;";

myLayer.property("position").expression = myExpr;


So I reworked it to reflect what you've put


applyButton.onClick = function(){
props = app.project.activeItem.selectedProperties;
for (var i = 0; i < props.length; i++){
if (props[i].canSetExpression){
props[i].expression = "input = thisComp.layer(\"[Colour]\").text.sourceText; if( (input == \"red\") == 1) value else 0;";
}
}


I was going to ask if there was a way to create a textStr in the expression, so you can put your own variable to your layers and click the button and it will add it to all those layers. Found another one of your wonderful threads and came up with this

applyButton.onClick = function(){
props = app.project.activeItem.selectedProperties;
textStr = addScript.text;
for (var i = 0; i < props.length; i++){
if (props[i].canSetExpression){
props[i].expression = "input = thisComp.layer("[Station]").text.sourceText; if((input == "" +textStr+ "") == 1) value else 0;";
}
}
}


I'm starting to enjoy this script building malarky.


Return to posts index

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