Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Script UI Not Detecting Variable

  • Script UI Not Detecting Variable

    Posted by John Wooltorton on March 9, 2019 at 12:59 pm

    Hello everyone, I am having a problem of detecting a variable in a text box. So basically what I want to do is to apply a pre-defined preset to whatever I typed into the text box. Now when I click the button, it creates an empty layer with the preset because apparently, it can’t detect the variable I give it.
    Here is the code, it may look like what a noob would have done because I am completely new to coding. More resources will be provided below…

    (function(thisObj){
    scriptBuildUI(thisObj)

    function scriptBuildUI(thisObj) {
    var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "ScriptUI Template", undefined);
    win.spacing = 5;

    var groupOne = win.add("group", undefined, "GroupOne");
    groupOne.orientation = "column";

    var myText = groupOne.add ("edittext", undefined, "");
    myText.characters = 30;
    // myText.active = true; // <--- This line I copied from the Internet, don't know what excatly it does
    myText.helpTip = "Please edit your text here"
    var myEditText = myText.text;

    var Button = groupOne.add("button", undefined, "Button");
    Button.onClick = function(){
    main('Bouncing_texts.ffx', myEditText); // FINAL FUNCTION!!!
    };

    win.onResizing = win.onResize = function() {
    this.layout.resize();
    };

    win instanceof Window
    ? (win.center(), win.show()) : (win.layout.layout(true), win.layout.resize());
    }

    // Add functions below this line

    // Applying Presets //
    var main = function(myFX, myEditText) {

    var proj = app.project;
    var folder = new Folder('C:/Program Files/Adobe/Adobe After Effects CC 2019/Support Files/Presets/User Presets/' + myFX);
    if (folder.exists !== true) {
    alert('Preset file does not exist');
    return;
    }

    app.beginUndoGroup('apply preset');

    var Composition = proj.activeItem;
    var myTextLayer = Composition.layers.addText(myEditText);
    var myTextSource = myTextLayer.sourceText;
    var myTextDocument = myTextSource.value;

    // var item = proj.activeItem;

    myTextLayer.applyPreset(folder);
    myTextSource.setValue(myTextDocument);

    app.endUndoGroup();
    // return 0;
    };
    // Function "Apply presets" Ends //

    })(this);

    Some more details here: https://imgur.com/0BGfNIy
    https://imgur.com/1soiSP4

    Any help is greatly appreciated!!

    John

    View post on imgur.com

    John Wooltorton replied 7 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Oleg Pirogov

    March 9, 2019 at 2:35 pm

    On the first glance: I would expect myEditText assignment to be in onClick event:

    Button.onClick = function(){
    var myEditText = myText.text;
    main('Bouncing_texts.ffx', myEditText); // FINAL FUNCTION!!!
    };

    or actually:
    Button.onClick = function(){
    main('Bouncing_texts.ffx', myText.text); // FINAL FUNCTION!!!
    };

  • John Wooltorton

    March 9, 2019 at 2:38 pm

    Button.onClick = function(){
    var myEditText = myText.text;
    main('Bouncing_texts.ffx', myEditText); // FINAL FUNCTION!!!
    };

    This worked!! Thank you so much 😀

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy