Highlighted

Checking panel visibility

Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

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? 

Topics

How to, Scripting

Views

134

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Checking panel visibility

Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

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? 

Topics

How to, Scripting

Views

135

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

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

 

ArtboardsFindReplace.gif

 

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

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. 

 

Screenshot 2020-07-04 at 10.53.05 PM.png

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

Unfortunately, it doesn't dock on my end. I'm on the Ai 24.2 Mac OS X. The panels open separately.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

It will not dock via script. First you have to dock manually once. And since they are dock together, when you run that code, always "Artboard" panel will be visible. You can use another panel to dock as well just make sure you have key for executeMenuCommand. In short here are the steps.

 

1. Open Navigator panel.

2. Open Artboard panel.

3. Dock together manually. This needs to be done only once.

4. Run above 2 line of code.

 

Let me know if it works for you.

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

Those panels that are visible are shown with checkmarks in the menu.

2020-07-04_20-48-55.png

That's why I thought that maybe there should be a way to detect their visibility via a script 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

That's correct what you are saying but I could not find anything in documentation. Also I am looking into Illustartor preferences files. Because there must be preefernces where this information will be stored, otherwise how Illustartor will remember which panel is open after quitting. If I found something from preferences files, I will definitely post.

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 04, 2020

Copy link to clipboard

Copied

Thank you so much for your help! The trick with the docked panels works for me. But it depends on the individual configuration. If the configuration changes, the trick may not work. It would be very good to find a more universal way.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

That's 100% correct. If you are the only person who is using script, then its fine to use this workaround but if your script is used by many customers, then ofcourse it is not the best solution.

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 04, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 05, 2020

Copy link to clipboard

Copied

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');

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 05, 2020

Copy link to clipboard

Copied

Thanks for your time, Charu 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 05, 2020

Copy link to clipboard

Copied

As elwinr71103972, quotes same things happen to me

 

With your code and undocked panels:

  1. If the Artboards panel isn't visible, it will open it. Result: Artboards is visible & active.
  2. If the Artboards panel is visible, it will close it. Result: the Artboards isn't visible.

 

What he wants, to always keep Artboards panel open to see the changes of name of artboards and following command actually toggles visibility of Artboards panel

app.executeMenuCommand('Adobe Artboard Palette');

So, we are finding a way, if it is already open, we will not run this command and if it is not open, then execute this command.

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 05, 2020

Copy link to clipboard

Copied

You're welcome elwinr71103972 🙂 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 05, 2020

Copy link to clipboard

Copied

Hi, Carlos, thanks for your reply))

 

With your code and undocked panels:

  1. If the Artboards panel isn't visible, it will open it. Result: Artboards is visible & active.
  2. If the Artboards panel is visible, it will close it. Result: the Artboards isn't visible.

 

With Charu's code above and docked panels:

All operations affect both of them.

  1. If the docked panel block is on the screen and the Artboards isn't visible (which means that Navigator is), the code will close Navigator (and Artboards with it), and than open Artboards (and Navigator with it, because they're docked). Result: Artboards is visible & active.
  2. If the docked panel block is on the screen and the Artboards is visible, the code will activate the Navigator first, and than activate the Artboards. Result: Artboards is visible & active.
  3. If the docked panel block isn't on the screen, the code will open it (both panels together) and than activate the Artboards. Result: Artboards is visible & active.

 

Conclusion: It's better to have them docked.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Contributor ,
Jul 04, 2020

Copy link to clipboard

Copied

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

app.redraw();

Sorry if I've misunderstood.

Mark

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 05, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Contributor ,
Jul 05, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 05, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 05, 2020

Copy link to clipboard

Copied

That's correct. You got it. 🙂

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...