Skip to main content
Legend
March 2, 2015
Question

Close dockable panel programmatically?

  • March 2, 2015
  • 1 reply
  • 497 views

Hi There,

Is it possible to simply close a dockable panel that my script creates with a line of code?  I thought I might be able to use the Window.find() method, but that doesn't seem to work.  Here is how I am instantiating the dockable panel (of course this assumes the user launches the script from the "Window" menu):

var win = (this.context instanceof Panel) ? this.context : new Window('palette', enums.panel_title, undefined, {resizeable : true});

So this creates the dock just fine, and gives it the title from the string found in `enums.panel_title`.  In a function of seperate and different another script, I would like to close that panel programmatically, so I tried this:

var existing_gui = Window.find('palette', enums.panel_title);

if (existing_gui)

    existing_gui.close();

And yet, `existing_gui` remains null even after the Window.find() call.

Thanks for your time and help!

--Arie

This topic has been closed for replies.

1 reply

UQg
Legend
March 2, 2015

Hi Arie,

i don't know how to do it but what is sure is that Panels are not "instanceof Window" so that Window.find won't find them.

And they also don't have a close() method.

You can try using

app.executeCommand(app.findMenuCommandId(xxx));

where xxx is the name of the script as it appears in the Window menu of the app (for instance "myScript.jsxbin").

One problem is: if you distribute the script and a user changes the script name (for instance to something shorter so that the tab is smaller) it won't work.

And another problem is that if the panel was already visible it actually closes it... and it is not obvious how to differentiate the two states.

May be try to keep a global variable/function somewhere that allows to check the validity of the panel, something like:

void function(thisObj){

    var win = (this.context instanceof Panel) ? this.context : new Window('palette', enums.panel_title, undefined, {resizeable : true}); 

     // script code goes there

   

    if (typeof $.global["ArieStuff"]!=='object') $.global["ArieStuff"] = {};

    ArieStuff.checkThisScriptPanel = function(){return Object.isValid(win);};

   

    return;

    }(this);

Then utside your script, you can do

if (ArieStuff.checkThisScriptPanel()) app.executeCommand(app.findMenuCommandId(xxx));

A little bit clumsy... but if the script is not renamed to something else it should work.

There might be something simpler though.

Xavier.

Legend
March 2, 2015

Xavier,

Thank you for your time and detailed thoughts, as well as your examples.  It seems like a good approach.  I'm not so much concerned about a user changing the name of the filename, and I agree that the app.executeCommand method would work if only it was possible to determine the state.  I will try your approach and see if I can get it working.

I appreciate your help, and will post back with my findings.

--Arie