Copy link to clipboard
Copied
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; // <---- I have no idea what this line does, copied from the Internet
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;
myTextLayer.applyPreset(folder);
myTextSource.setValue(myTextDocument);
app.endUndoGroup();
};
// Function "Apply presets" Ends //
})(this);
Some more details here: https://imgur.com/0BGfNIy
Any help is greatly appreciated!!
Jason
So! It's a small thing, but what you're doing is:
When the window is created, set myEditText to be the contents of the text field (which is blank)
When the button is pressed, return the value of myEditText that you set before (which is a blank string).
What you need to do instead is to get the value of myEditText on button press, not before; just define the value within the button click.
From:
...var myEditText = myText.text;
var Button = groupOne.add("button", undefined, "Button");
Button.onClick = funct
Copy link to clipboard
Copied
So! It's a small thing, but what you're doing is:
When the window is created, set myEditText to be the contents of the text field (which is blank)
When the button is pressed, return the value of myEditText that you set before (which is a blank string).
What you need to do instead is to get the value of myEditText on button press, not before; just define the value within the button click.
From:
var myEditText = myText.text;
var Button = groupOne.add("button", undefined, "Button");
Button.onClick = function() {
main("Bouncing_texts.ffx", myEditText); // FINAL FUNCTION!!!
};
To:
var Button = groupOne.add("button", undefined, "Button");
Button.onClick = function() {
var myEditText = myText.text;
main("Bouncing_texts.ffx", myEditText); // FINAL FUNCTION!!!
};
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more