Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to change a value in an expression with a dropdown menu in ExtendScript?

Explorer ,
Mar 27, 2019 Mar 27, 2019

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.

TOPICS
Scripting
988
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 28, 2019 Mar 28, 2019

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

...
Translate
Advocate ,
Mar 28, 2019 Mar 28, 2019
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines