Copy link to clipboard
Copied
Hey, I'm Bram Hoekstra. I'm from the Netherlands and I'm fairly new to AE Scripting.
I'm curious if it's possible to change a value in an expression by using a dropdown menu.
I've tried to embed the function of the dropdown selector in the expression but that didn't seem to work.
Can someone please help me out with this.
Well, it involves a few steps:
1. Read expression,
2. Change value,
3. Apply modified expression back to the property.
If you could post an example of what you've got so far, that would make it easier to help. However, here's a small snippet that shows how to apply the expression to a property. Feel free to take it apart and please let me know if you don't understand something.
...(function (thisObj) {
buildUI(thisObj);
function buildUI(thisObj) {
var win = (thisObj instanceof Panel) ? this
Copy link to clipboard
Copied
Well, it involves a few steps:
1. Read expression,
2. Change value,
3. Apply modified expression back to the property.
If you could post an example of what you've got so far, that would make it easier to help. However, here's a small snippet that shows how to apply the expression to a property. Feel free to take it apart and please let me know if you don't understand something.
(function (thisObj) {
buildUI(thisObj);
function buildUI(thisObj) {
var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {
resizeable: true
});
var names = ['Expression 1', 'Expression 2'];
var expressions = ['// Expression 1;\nvalue', '// Expression 2;\nvalue'];
var ddSelection = win.add('dropdownlist', undefined, names);
ddSelection.selection = 0;
var btnAddExpression = win.add('button', undefined, 'Add Expression');
btnAddExpression.onClick = function() {
var expression = expressions[ddSelection.selection.index];
addExpression(expression);
};
win.onResizing = win.onResize = function () {
this.layout.resize();
};
if (win instanceof Window) {
win.center();
win.show();
} else {
win.layout.layout(true);
win.layout.resize();
}
}
function addExpression(expression) {
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem)) {
return alert('Please select composition first');
}
if (composition.selectedProperties.length !== 1) {
return alert('Please select one property to apply expression to');
}
var property = composition.selectedProperties[0];
app.beginUndoGroup('Add Expression');
property.expression = expression;
app.endUndoGroup();
}
})(this);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now