Skip to main content
Wul Voraz
Inspiring
June 10, 2016
Answered

How to change Source Text with EditText in my Script?

  • June 10, 2016
  • 3 replies
  • 1757 views

Here is my actually code, the thing is that i want to change my text from myEditText in my Panel:

function myScript(thisObj) {

          function myScript_buildUI(thisObj) {

                    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);

                    res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                              myEditText: EditText{text:'EditText text'},\

                              myButton: Button{text:'Button Name'},\

                    }"

                    //Add resource string to panel

                    myPanel.grp = myPanel.add(res);

                   

                   

                    var texto = myPanel.grp.myEditText.text.value

                   

                    var btn =  myPanel.grp.myButton

                   

                   

                   

                    btn.onClick = function (){

                       

                        app.project.item(2113).layer("TXT 1").property("Text").property("Source Text").setValue = texto

                       

                        }

                   

                   

                   

                   

                    //Setup panel sizing and make panel resizable

                    myPanel.layout.layout(true);

                    myPanel.grp.minimumSize = myPanel.grp.size;

                    myPanel.layout.resize();

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

                    return myPanel;

          }

          var myScriptPal = myScript_buildUI(thisObj);

          if ((myScriptPal != null) && (myScriptPal instanceof Window)) {

                    myScriptPal.center();

                    myScriptPal.show();

                    }

          }

          myScript(this);

This topic has been closed for replies.
Correct answer Osama Sa

Something like this should work:

function myScript(thisObj) {

  var textStr = "";

  function myScript_buildUI(thisObj) {

  var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]); 

  res = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

  myEditText: EditText{text:'EditText text'},\

  myButton: Button{text:'Button Name'},\

  }"

  //Add resource string to panel 

  myPanel.grp = myPanel.add(res);

  // I added the next two lines.

  textStr = myPanel.grp.myEditText.text;

  myPanel.grp.myEditText.onChange =  myPanel.grp.myEditText.onChanging = textStringUpd;

  myPanel.grp.myButton.onClick = function (){

  app.project.item(2113).layer("TXT 1").sourceText.setValue(textStr);

  //or tell the script to change the soureText property of the currently selected layer (remove the two slashes from the line below and add them to the line above)

  //app.project.activeItem.selectedLayers[0].sourceText.setValue(textStr);

  }

  //Setup panel sizing and make panel resizable

  myPanel.layout.layout(true);

  myPanel.grp.minimumSize = myPanel.grp.size;

  myPanel.layout.resize();

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

  return myPanel;

  } 

  var myScriptPal = myScript_buildUI(thisObj);

  // I added this function.

  function textStringUpd() {

  textStr = this.text;

  }

  if ((myScriptPal != null) && (myScriptPal instanceof Window)) { 

            myScriptPal.center(); 

  myScriptPal.show(); 

  } 

  } 

myScript(this); 

I added comments to let you know the changes I've made

3 replies

Participant
July 2, 2019

Hi how my I use this script ? THANKS

Osama Sa
Osama SaCorrect answer
Inspiring
June 12, 2016

Something like this should work:

function myScript(thisObj) {

  var textStr = "";

  function myScript_buildUI(thisObj) {

  var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]); 

  res = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

  myEditText: EditText{text:'EditText text'},\

  myButton: Button{text:'Button Name'},\

  }"

  //Add resource string to panel 

  myPanel.grp = myPanel.add(res);

  // I added the next two lines.

  textStr = myPanel.grp.myEditText.text;

  myPanel.grp.myEditText.onChange =  myPanel.grp.myEditText.onChanging = textStringUpd;

  myPanel.grp.myButton.onClick = function (){

  app.project.item(2113).layer("TXT 1").sourceText.setValue(textStr);

  //or tell the script to change the soureText property of the currently selected layer (remove the two slashes from the line below and add them to the line above)

  //app.project.activeItem.selectedLayers[0].sourceText.setValue(textStr);

  }

  //Setup panel sizing and make panel resizable

  myPanel.layout.layout(true);

  myPanel.grp.minimumSize = myPanel.grp.size;

  myPanel.layout.resize();

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

  return myPanel;

  } 

  var myScriptPal = myScript_buildUI(thisObj);

  // I added this function.

  function textStringUpd() {

  textStr = this.text;

  }

  if ((myScriptPal != null) && (myScriptPal instanceof Window)) { 

            myScriptPal.center(); 

  myScriptPal.show(); 

  } 

  } 

myScript(this); 

I added comments to let you know the changes I've made

Wul Voraz
Wul VorazAuthor
Inspiring
June 13, 2016

Hey, thank you very much, is there a way to just change in real time the text On Change??? without button?

Osama Sa
Inspiring
June 13, 2016

So you want to the text layer to update dynamically while you're typing in the text field of your script without having to click on the button? Or did I get you wrong?

Participating Frequently
June 11, 2016

Try something like this:

//1 take a layer(for example here first selected layer in current active composition)

var TEXTLAYER = app.project.activeItem.selectedLayers[0];

//2 take a text from edit text box

var TEXT = editText.text.value;

//and use setValue() function

TEXTLAYER.sourceText.setValue(TEXT);

Good luck=)