FORUMS: list search recent posts

Script UI Not Detecting Variable

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Wooltorton
Script UI Not Detecting Variable
on Mar 9, 2019 at 12:59:19 pm
Last Edited By John Wooltorton on Mar 9, 2019 at 1:00: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


Return to posts index

Oleg Pirogov
Re: Script UI Not Detecting Variable
on Mar 9, 2019 at 2:35:03 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!!!
};


Return to posts index

John Wooltorton
Re: Script UI Not Detecting Variable
on Mar 9, 2019 at 2:38:54 pm

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


This worked!! Thank you so much :D


Return to posts index

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