Skip to main content
Elwin_Ransom
Participating Frequently
July 4, 2020
Question

Checking panel visibility

  • July 4, 2020
  • 4 replies
  • 1565 views

Hello!

I am trying to write a script that searches/replaces text in the name list in the Artboards panel. After the replacement is done, the name list needs to be refreshed so that the new names are displayed. I do this with the next trick:

  function reopenPanel() {
  // Illustrator UI trick: Reopen Artboards panel to refresh names 
    app.executeMenuCommand('Adobe Artboard Palette'); // close
    app.executeMenuCommand('Adobe Artboard Palette'); // open
  }

But for this purpose it is necessary that at the start of the script the Artboards panel was already open and displayed on the screen. Is there any way to check if the panel is open and visible on the screen? 

This topic has been closed for replies.

4 replies

CarlosCanto
Community Expert
Community Expert
July 5, 2020

Hi Charu and Elwin, oh I see, if the Artboard panel is detached (floating) it will not work.

Charu Rajput
Community Expert
Community Expert
July 5, 2020

That's correct. You got it. 🙂

Best regards
m1b
Community Expert
Community Expert
July 4, 2020

Hi elwinr71103972, I may not understand your question right, but I think the answer might be:

app.redraw();

Sorry if I've misunderstood.

Mark

Elwin_Ransom
Participating Frequently
July 5, 2020

Hi, Mark, and thank you!

"app.redraw" is really better and easier than trick with "executeMenuCommand" (how could I forget about it!). But that's not exactly the answer. It would be very good to find a way to detect panel activity, but as I see it is not yet possible to do so.

m1b
Community Expert
Community Expert
July 5, 2020

Another approach could be to make a ListBox and populate it with the artboard names and manipulate that, only at the last minute applying the changes to the actual document. Just a thought, seeing as you seem comfortable with ScriptUI.

 

Mark

CarlosCanto
Community Expert
Community Expert
July 4, 2020

the panels don't have to be docked, why don't you just execute Navigator (or any other panel) twice before executing Artboards? that way Navigator doesn't remain open if it wasn't open before.

Charu Rajput
Community Expert
Community Expert
July 5, 2020

Hi Carlos,

I tried but I was unable to get the results. Apart from this, can't we easily check whether panel is already open or not.  I could not find any such information in Illustrator preferences file.

Best regards
CarlosCanto
Community Expert
Community Expert
July 5, 2020

Hi Charu, this didn't work for you? It works for me, panels don't need to be docked togheter

 

app.executeMenuCommand('AdobeNavigator');
app.executeMenuCommand('AdobeNavigator');
app.executeMenuCommand('Adobe Artboard Palette');
Charu Rajput
Community Expert
Community Expert
July 4, 2020

Hi,

To search and replaces text in the name list of the Artboards panel, there is no need to open the Artboards panel. You can use following snippet to replace the name of the artboards without opening and closing it. Name will be automatically refreshed.

var doc = app.activeDocument;
var _artboards = doc.artboards;
for (var a = 0; a < doc.artboards.length; a++) {
	if (_artboards[a].name == 'Artboard 1') {
		_artboards[a].name = "New Name";
	}
}

 

You can use your own logic of serach/replace inside the for loop. In the above snippet, it is searching for the artboard with name "Artboard 1" and replacing it with name "New Name".

 

Let me know if this helps you.

Best regards
Elwin_Ransom
Participating Frequently
July 4, 2020

Thanks for your answer, Charu Rajput. Please, look at the animation of how this script works.

 

 

In this case I really need to see the result of my replacements, because the replacements can be more than one. That's why I thought it would be a good idea to make sure that the panel is open and visible when the script runs.

Charu Rajput
Community Expert
Community Expert
July 4, 2020

Hi,

As far as I know, I don't think we can check whether panel is open or not via script. But you can have one work around. You can dock any another panel with artboard and then use the following snippet.

 

 

app.executeMenuCommand('AdobeNavigator');
app.executeMenuCommand('Adobe Artboard Palette');

 

 

Here I have dock Navigator panel with Artboard window. So by executing this, first it will take focus to Navigator Window and then focus to 'Artboard' panel. See below screen shot how I dock together. 

 

By executing above code you will always see Artboard panel open. This is just a workaround.

Let us know if this works for you.

Best regards