• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
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

246

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
Adobe
Participant ,
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.

Votes

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.

Votes

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
Participant ,
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! 🙂

Votes

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.

 

Votes

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
Participant ,
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.

Votes

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. 😃

Votes

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

"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.

 

Votes

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
Participant ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

For the guides, I figured out a hack that will let you determine if they're visible or not. If you "select all" in your document while paths are unlocked but hidden, they won't show up in app.activeDocument.selection. I wondered if this could be done at the time of adding guides, and it turns out, if you try to set the .selected property of a pathItem that is a guide to true while the guides are hidden, it'll still resolve to false 🙃.

 

 

 

function guidesAreVisible() {
  if (!app.activeDocument) return false

  // Create a path object
  var path = app.activeDocument.pathItems.add()
  path.guides = true
  path.selected = true

  // If guides are not visible, this will be false, believe it or not.
  var visible = path.selected

  // Clean up
  path.remove()

  return visible
}

 

Votes

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
Participant ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

LATEST

Edit: Don't use my snippet above. It doesn't work when guides are locked. The locked state of guides are also unfortunatelly a value we can't query the state of. I tried to figure this out, but ultimately failed. Here's what I tried:

 

I figured, if run the check twice, and switch the lock status in between, at least one of the two tries will happen while guides are unlocked, and thus, at least one success indicates that the guides are visible. 

 

The whole scenario depends on deterministic treament of the ability to select a guide, in this case, the assumption that you can't select a guide that is hidden. This is true!… as long as you don't change anything.

 

I unfortunatelly discovered that of you toggle the locked status of guides, regardless of the state it ends in, if you try to select a guide as second time it will be selected (despite this not being the case before doing the toggle).

 

I've ultimately abandonned trying to detect the visibility state.

Votes

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