Copy link to clipboard
Copied
This is the layout I was fallowing while creating my GUI.
https://www.goodboy.ninja/snippets/dockable-scriptui-panel-template
I can disable buttons easily with buttonName.enabled = false; but I couldn't make it work from another window.
By the way, the "another window" I am speaking about still part of the script. It is opening when I click "Help" button.
So here's an example where, if you were trying to stop multiple help windows from being created, that's no longer a problem as this will only create one if necessary.
But just for the hell of it, I also stuck in an example that turns the help button on the main panel on/off. Don't really know what you're trying to do here but hopefully this will give you all the info you need.
function myAwesomeScript(thisObj) {
var helpWindow; // define in main script scope so it's accessible throughout
fu
...
Copy link to clipboard
Copied
I guess the problem is that any variables you define inside the buildUI function are only accessible within that function. That is how variable scope works with functions. So one solution might be to just put...
var myPanel;
...at the top inside your main function, then remove the 'var' from where you assign 'var myPanel' inside the buildUI function. And now the myPanel variable will be accessible throughout the scope of the outer function which will presumably include all your code.
Typically I'll do it more like....
var thePanel = buildUI(thisobject);
...and then right at the end inside of the buildUI function I'd put...
return myPanel;
so the panel object is returned from the buildUI function and assigned to 'thePanel' variable.
In theory you should be able to access all the child elements of the panel object like thePanel.myGroup.myButton but that may depend on how you're creating your UI. At the very least if you're doing something like myButton = myPanel.add(... then again you just need to initially define 'var myButton' in the outer function scope and not use var inside the buildUI function. It's hard to give you anything other than a general answer without seeing the code you're using to create your UI elements.
Typically I create my UIs this way:
https://extendscript.docsforadobe.dev/user-interface-tools/resource-specifications.html
as opposed to using the line by line myPanel.add(
Copy link to clipboard
Copied
Hey Paul, thanks for the help again 🙂
// GUI
buildUI(thisObj);
function buildUI(thisObj) {
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("window", undefined, undefined, {resizeable: false});
//myPanel.text = "Expression Controller";
myPanel.orientation = "row";
myPanel.alignChildren = ["left", "top"];
myPanel.spacing = 10;
myPanel.margins = 10;
...
var help = myPanel.add("button", undefined, undefined);
help.helpTip = "Help";
help.text = "?";
help.preferredSize.width = 27;
help.preferredSize.height = 27;
help.alignment = ["left", "center"];
...
help.onClick = function () {
var helpWindow = new Window("dialog","Help - About",undefined,{resizeable:false});
about(helpWindow);
};
...
function about(helpWindow){
helpWindow.orientation = "column";
helpWindow.alignChildren = ["center","top"];
helpWindow.spacing = 12;
helpWindow.margins = 15;
helpWindow.show();
}
})(this);
This is how I built it. I can't say I understand what do you mean to be honest, can you give another example?
Copy link to clipboard
Copied
Are you saying you want to stop the user from being able to click the help button again once the help window is open?
Copy link to clipboard
Copied
So here's an example where, if you were trying to stop multiple help windows from being created, that's no longer a problem as this will only create one if necessary.
But just for the hell of it, I also stuck in an example that turns the help button on the main panel on/off. Don't really know what you're trying to do here but hopefully this will give you all the info you need.
function myAwesomeScript(thisObj) {
var helpWindow; // define in main script scope so it's accessible throughout
function buildUI(thisObj) {
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", undefined, undefined, {resizeable: false});
//myPanel.text = "Expression Controller";
pal.orientation = "row";
pal.alignChildren = ["left", "top"];
pal.spacing = 10;
pal.margins = 10;
pal.help = pal.add("button", undefined, undefined);
pal.help.helpTip = "Help";
pal.help.text = "?";
pal.help.preferredSize.width = 27;
pal.help.preferredSize.height = 27;
pal.help.alignment = ["left", "center"];
pal.help.onClick = function () {
if (helpWindow == null || helpWindow.visible == false) buildHelp(); // only create helpWindow if it isn't already visible
else helpWindow.show();
};
return pal // return panel object
}
function buildHelp() {
helpWindow = new Window("palette","Help - About",undefined,{resizeable:false});
helpWindow.orientation = "column";
helpWindow.alignChildren = ["center","top"];
helpWindow.spacing = 12;
helpWindow.margins = 15;
var test = helpWindow.add("button", undefined, "Try Me!");
test.onClick = function() {
if (myPanel.help.enabled == true) myPanel.help.enabled = false; // here's an example of now being able to access the UI from outside the scope of the buildUI function
else myPanel.help.enabled = true;
}
helpWindow.onClose = function() {
myPanel.help.enabled = true; // just in case you left it turned off
}
helpWindow.show();
}
var myPanel = buildUI(thisObj); // receive panel object. define in main script scope so it's accessible throughout
if (myPanel != null) {
if (myPanel instanceof Window) {
myPanel.center();
myPanel.show();
}
}
}
myAwesomeScript(this);
Copy link to clipboard
Copied
What I was trying to do was your text example, but not for the help button. I managed to make it work in your example but for some reason I couldn't in my script. To make it work I had to rewrite a lot, so I gave up. I managed to find a workaround for it tho, so it is ok : D
I just want to ask one last question (irrelevant from the post). When I launch the script via Window menu to make it dockable, it launches like this. Is there a way to set a "launch size" or something like that? I can change manually without a problem so it is not a big issue, but I am just curious to learn if it is possible or not : )
Copy link to clipboard
Copied
Off the top of my head, I don't think so. But I think it remembers the panel state between launches so if you close it, when you reopen it it'll be the size / location where last used. I would imagine that since docked panels just assume the size of where they are docked, that is why you can't specifically set their size.
Copy link to clipboard
Copied
Oh and if the reason you couldn't get it to work in your script without rewriting was just because you weren't using:
pal.help = pal.add...(which makes it easy to access everything through the parent panel object)
but were instead using:
var myButton = myPanel.add...
you could have just had:
var myButton;
up at the top then:
myButton = myPanel.add...
and then myButton would have been accessible throughout.
Maybe that wasn't your 'need to rewrite' problem, but I just realised that although I explained this variable /function scope stuff I hadn't explicited shown this exact example.
Copy link to clipboard
Copied
I probably could've written it better, but I saw that website and created my GUI with it. I think it turn out good enough though.
https://scriptui.joonas.me/