Need a script to toggle three settings at once and keep them synchronized.

Explorer ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

I often work with icons and need to quickly check how they look with pixel preview. When I'm building them I have the grid enabled, and artboards visible.

I really want a script that will do the following in one click:

1. Hide Artboards

2. Hide all guides

3. Hide the grid

4. Toggle Pixel Preview to ON.

And then another script that will exactly reverse the above toggles.

I tried recording an action to do this, but it doesn't pick up the "Hide Artboards", "Hide Grid", and "Toggle Pixel Preview" commands. It does however let me hide the guides, but that's kind of useless without the other three options.

Sorry for the double post. If anyone can point me to a script that does this, or a way I can do this myself, that would be fantastic. Thanks again.

Jay

TOPICS
Draw and design , Feature request , Scripting , Third party plugins , Tools

Views

82

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
community guidelines
Explorer ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

Just wanted to update. I got the correct menu commands and I'm calling them via app.executeMenuCommand. Here's the script sofar:

//@target illustrator
preferences.setBooleanPreference("ShowExternalJSXWarning", false); // Fix drag and drop a .jsx file

function main() {
   var SCRIPT = {
      name: "Toggle Preview Mode",
      version: "v.0.1"
   };

   if (!documents.length) {
      alert("Error\nOpen a document and try again");
      return;
   }
   app.executeMenuCommand("showgrid");
   app.executeMenuCommand("showguide");
   app.executeMenuCommand("raster");
   app.executeMenuCommand("artboard");
}

try {
   main();
} catch (e) {}

But the problem is if the grid is already hidden, the script will toggle it back on when I want to hide it. Likewise
with guides / pixel preview / artboard visibility. Is there a way to query the state of each property? Basically I want to do this: (excuse the psuedo code)

if(guidesAreHidden=true){ //do nothing }
if(gridIsHidden=true){ //do nothing }
if(pixelPreviewIsOn=true){ //do nothing }
if(artboardsAreHidden=true){//do nothing }

Or a more complex example (Only the grid is hidden):

if(guidesAreHidden=false) { app.executeMenuCommand("showguide"); }
if(gridIsHidden=true){ //do nothing }
if(pixelPreviewIsOn=false){ app.executeMenuCommand("raster"); }
if(artboardsAreHidden=false){ app.executeMenuCommand("artboard"); }


Basically I need a way to retrieve whether guides/grid/pixel preview/artboard visibility is currently enabled or disabled so I can set the appropriate state.

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
community guidelines
Community Expert ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

hmmm. that's a noodle scratcher. I don't think there's any way to query the state of those things.. Sometimes you can get away with using actions for things like this, because certain actions include extra properties which are missing from the menuCommands.. as an example, if you start recording an action, then press cmd/ctrl + ; to toggle your guides visibility, the actions panel will populate with a new line called "Show Guides" which has a dropdown arrow you can click which will reveal the setting that will be used. So.. to answer PART of your question... you can show/hide the guides accurately with an action, despite the toggling uncertainty with executeMenuCommand()...

 

however.... grid, pixel preview, and hide artboards do not populate the same way in the actions panel.. The only way to get them in there is via "Insert Menu Command". Doing so does not include the desired state like Show Guides does.

 

I thought i had a brilliant idea for a quick second.. I thought maybe you could make a new "view" at the very bottom of the View menu, after setting up the document with all of these preview options.... And evidently the ONLY thing that gets saved in a "view" is the size/position of the artboard on the drawing area.... so..... not helpful.

 

I have a vague recollection of tackling at least one of these in the past.. but i can't find it at the moment, and the longer i think about it, the more sure i am that i only tackled the guides thing, and my solution was "use an action.." I'd definitely love to hear if anyone else has thoughts on this though. it would definitely be useful.

 

Only thing i can think of would be some kind of 3rd party UI automator that can click certain coordinates on a certain timeframe... But that's gonna be clunky and not at all portable.

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
community guidelines
Explorer ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

Thanks so much for the detailed response. It's unfortunate that this really isn't possible.

quote

Only thing i can think of would be some kind of 3rd party UI automator that can click certain coordinates on a certain timeframe... But that's gonna be clunky and not at all portable.

 

Rather than go with a UI automator like AHK, do you think this would be possible with a CEP or UXP plugin? I'm not adverse to coding my own plugin as I've been meaning to dive into plugin development for awhile.

If you have any more flashes of brilliance, let me know! 🙂

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
community guidelines
Community Expert ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

As an alternative for simultaneously reviewing your icons you may consider to set up your files with multiple windows.

 

That is, open one of your Illustrator files, go to the Window menu, choose "New Window" and arrange the two windows side by side. In the new window hide the artboard, guides, the grid and turn on Pixel Preview. Save the file.

 

In the original window (with artboard, guides and grid turned on) you can now modify the icon. In the second window (with artboard, guides and grid turned off) you will then immediately see all changes.

 

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
community guidelines
Explorer ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

Yup, that's what I've beem doing thus far. But it's a PITA when this kind of thing should be automatable.

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
community guidelines
Community Expert ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

IMO, every option in the "View" panel should be controlled by the "views". Like when you choose View > New View, it should save all of the currently selected view settings into that "view" object. As far as I can tell, a "view" only refers to the amount of the drawing area visible in the window.

 

It may be possible to do this with an extension/CEP. CEP panels have more access than extendscript.. Unfortunately I don't know CEP and with UXP appearing to be the imminent replacment as the dominant tech stack, i don't think it's worth investing in learning CEP at this point... People who know better than me... prove me wrong, please. 😃

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
community guidelines
Community Expert ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

LATEST

"As far as I can tell, a "view" only refers to the amount of the drawing area visible in the window."

 

Not quite.

 

Custom Views do also honour different visibility states and "locked" states of (main) layers in the Layers palette (though not as versatile as Visibility variables created with the Variables palette which do support sublayers as well).

 

Unfortunately, that won't help in this case.

 

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
community guidelines

Save time with Adobe Express quick actions