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

Script UI Not Detecting Variable

New Here ,
Mar 09, 2019 Mar 09, 2019

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

https://imgur.com/1soiSP4

Any help is greatly appreciated!!

Jason

915
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

Contributor , Apr 20, 2019 Apr 20, 2019

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

...
Translate
Contributor ,
Apr 20, 2019 Apr 20, 2019
LATEST

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!!!

};

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