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

How to avoid repeating call when the panel has not been closed in script?

Engaged ,
Dec 30, 2023 Dec 30, 2023

I have written two JSX scripts,
where clicking a button in panel A calls another script from panel B.
However, the current way of calling causes the panel to be repeated every time the button is clicked on panel A.
How can I avoid repeating the call when the panel has not been closed?
For example, if panel B's script is still running and the button on panel A is clicked again without closing it,
it should not repeat the call.
Here is an example code:

var panelA = new Window("palette", "PanelA", undefined);
var button = Apanel.add("button", undefined, "Button");

button.onClick = function() {
panelB();
}
panelA.show();

function panelB () {
var panelB = new Window("palette", "PanelB", undefined);
var button2 = PanelB.add("button", undefined, "Button2");
button2.onClick = function() {
alert("this is panelB")
}
panelB.show();
}

TOPICS
Scripting
1.1K
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

Advocate , Dec 31, 2023 Dec 31, 2023

In this case enable the button when you close panelB

    var panelA = new Window("palette", "PanelA", undefined)
    var button = panelA.add("button", undefined, "Button")

    button.onClick = function() {
      panelB()
      this.enabled = false; // disable the button
    }
    panelA.show();

    function panelB() {
      var panelB = new Window("palette", "PanelB", undefined)
      var button2 = panelB.add("button", undefined, "Button2")
      button2.onClick = function() {
        alert("th
...
Translate
Advocate ,
Dec 30, 2023 Dec 30, 2023

You can disable the button:

var panelA = new Window("palette", "PanelA", undefined);
var button = panelA.add("button", undefined, "Button");

button.onClick = function() {
  panelB();
  this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
  var panelB = new Window("palette", "PanelB", undefined);
  var button2 = panelB.add("button", undefined, "Button2");
  button2.onClick = function() {
    alert("this is panelB")
  }
  panelB.show();
}

 

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
Engaged ,
Dec 31, 2023 Dec 31, 2023

But if the button is disabled, when panel B closes, it won't be able to call again by push button.

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
Advocate ,
Dec 31, 2023 Dec 31, 2023

In this case enable the button when you close panelB

    var panelA = new Window("palette", "PanelA", undefined)
    var button = panelA.add("button", undefined, "Button")

    button.onClick = function() {
      panelB()
      this.enabled = false; // disable the button
    }
    panelA.show();

    function panelB() {
      var panelB = new Window("palette", "PanelB", undefined)
      var button2 = panelB.add("button", undefined, "Button2")
      button2.onClick = function() {
        alert("this is panelB")
      }
      panelB.onClose = function() {
        button.enabled = true
      }
      panelB.show()
    }
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
Engaged ,
Dec 31, 2023 Dec 31, 2023

Thank you, this approach is effective.

In addition, I have two more questions.
1. Is there a better way to merge two JSX elements into one by calling a button?
2. How can I refresh the Panel A when changing the button number in Panel B through its button?
Here is an example:

var panelA = new Window("palette", "PanelA", undefined)
var button = panelA.add("button", undefined, "Button")

button.onClick = function() {
panelB()
this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
var panelB = new Window("palette", "PanelB", undefined)
var button2 = panelB.add("button", undefined, "Button2")

button2.onClick = function() {
var button3 = panelA.add("button", undefined, "Button3")
}

panelB.onClose = function() {
button.enabled = true
}


panelB.show()
}

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
Advocate ,
Dec 31, 2023 Dec 31, 2023

To refresh the panel, you can use:

panelA.layout.layout(true); // refresh the panel

 

var panelA = new Window("palette", "PanelA", undefined)
var button = panelA.add("button", undefined, "Button")

button.onClick = function() {
  panelB()
  this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
  var panelB = new Window("palette", "PanelB", undefined)
  var button2 = panelB.add("button", undefined, "Button2")

  button2.onClick = function() {
    var button3 = panelA.add("button", undefined, "Button3")
    panelA.layout.layout(true); // refresh the panel
  }

  panelB.onClose = function() {
    button.enabled = true
  }
  panelB.show()
}

 

 

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
Engaged ,
Dec 31, 2023 Dec 31, 2023
LATEST

Thank you very much.
If I use the file calling JSX method, how can I check if a window is close and set the value to true?


if (file.exists) {
$.evalFile(file);
}

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
Explorer ,
Dec 31, 2023 Dec 31, 2023

To prevent repeated instantiation of Panel B, add a check within panelB function to see if the panel is already open before creating a new instance. You can use a flag variable like isPane1B0pen and set it to true when the panel is created, then check this flag before creating the panel again.

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
Engaged ,
Dec 31, 2023 Dec 31, 2023

I have tried using the example with a flag to check if Panel B is open or not, but I want to make Panel B the focus when the flag is true. However, using

if(isPane1B0pen == false){

panelB();

} else {

panelB.show();

}

does not move the focus to Panel B after clicking on it. Have I made a mistake somewhere?

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