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:
Hide Artboards
Hide all guides
Hide the grid
Toggle Pixel Preview to ON.
And then another script that will exactly reverse the above toggles.
Unfortunately I can't find a way to query the state of the application to determine if artboard borders are already hidden, or if the grid is already hidden, etc.
This is the simple script right now:
//@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"); }
Essentially 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 of the application.
Any help greatly appreciated.
Edit1:
I just want to add that if this can be done with a custom CEP or UXP plugin rather than a script, I would love to hear how. I am not adverse to programming my own plugin to accomplish this feature. I've been meaning to dive into CEP/UXP plugin authoring for awhile now anyway.