Skip to main content
Participant
April 19, 2024
Question

Adding controls to a panel from a function in another file does not work

  • April 19, 2024
  • 0 replies
  • 124 views

Good day. I have a problem where, when you place your functions that add controls to a panel in another file, then they don't work. Have a look at this example:

 

This works fine (when everything is in one file):

# myFile.jsx

myButton.onClick = function () {
    var myWindow = new Window("dialog", "My Dialog");
    var myPanel = myWindow.add("panel", undefined, "Panel Title");
    myPanel.alignment = "fill";
    localAddButton(myPanel);
    myWindow.show();
}

function localAddButton(panel) {
    panel.add("button", undefined, "OK");
}

But this does not work (when things live in different files):

# myFile.jsx

#include "otherFile.jsx"
myButton.onClick = function () {
    var myWindow = new Window("dialog", "My Dialog");
    var myPanel = myWindow.add("panel", undefined, "Panel Title");
    myPanel.alignment = "fill";
    otherAddButton(myPanel);
    myWindow.show();
}

# --------------------------------------------------------------

# otherFile.jsx

function otherAddButton(panel) {
    panel.add("button", undefined, "OK");
}

Note that this is definitely not a problem with my include or paths or anything. I can import functions and variables just fine. This is a small example, but in practise this is quite a large hinderance to a project because it means all our tools need to live in one single file. Or we have to copy-paste the same functions into multiple files. Is there any temporary solution to this issue?

 

This topic has been closed for replies.