Reply To: Object Layer Options Scripting

#61545

It was easy – – surprisingly so! Kasyan's script did all the work, but he checks explicitly for a placed InDesign page. It took only a little check to find out under what name a placed Photoshop image is stored (see the commented-out “alert” line in my version below). It turned out to be a type of “Image” with a link type of “Photoshop” …

… (After about half an hour of head scratching..)

In fact it was so easy I decided to take it to the next level :) I added a little dialog that shows a selection of checkboxes, and you can turn each one on or off as you wish. The “layer names” list does not come from your placed images — although it is possible to read all of them, you'd get a load of extra names as well. You can adjust the list of names near the top of the function “Main”.

An oddity I ran into: it seems changing layer visibility invalidates the image and re-creates the link! That lead to the aforementioned bout of head-scratching, as suddenly “in the middle of the script”, it would report that the referenced image had disappeared! So I took a shortcut here: “refresh” the link on line 43, rather than re-using the loaded variable “placedFile”. Oh well, that's the sort of thing I do for fun.

So here is the script; it seems wrapping it up inside {pre} and {code} tags defeat WordPress post-beautifications (curly quotes, en-dashed) but if not, at least now you know what to look for.

Main();

function Main()
{
var page, placedFile, links, layer, i, j, k,
doc = app.activeDocument,
pages = doc.pages;
var checklist = [];

var layernames = [ “English”, “French”, “Dutch”, Russian ];

var ilDialog = app.dialogs.add({name:”Image Layers on/off”, canCancel:true});
with (ilDialog)
{
with(dialogColumns.add())
{
with(dialogRows.add())
{
staticTexts.add ({staticLabel:”Check to show, uncheck to hide”});
for (i=0; i<layernames.length; i++)
{
with(dialogRows.add())
checklist.push (checkboxControls.add({staticLabel:layernames[i], checkedState:false}));
}
}
}
}
var numChanges = 0;
var imageChange;
if (ilDialog.show() == true)
{
links = doc.links;
for (i = links.length-1; i>=0; i–)
{
placedFile = links[i].parent;
// show the internal type of this image:
// alert (placedFile.constructor.name+” / “+placedFile.itemLink.linkType);
if (placedFile.constructor.name == “Image” && placedFile.itemLink != null && placedFile.itemLink.linkType == “Photoshop”)
{
imageChange = false;
for (k=0; k<layernames.length; k++)
{
layer = links[i].parent.graphicLayerOptions.graphicLayers.item(layernames[k]);
if (layer.isValid && layer.currentVisibility != checklist[k].checkedState)
{
layer.currentVisibility = checklist[k].checkedState;
imageChange = true;
}
}
if (imageChange)
numChanges++;
}
}
alert(“Done, made changes in “+numChanges+” images”);
} else
{
ilDialog.destroy();
}
}

This article was last modified on January 25, 2012

Comments (0)

Loading comments...