I have a load of placed InDesign files on a page, each one has a layer called Frames. Is there a way to script Object Layer Options to go through and turn the visibility off for that specific layer to save me going through each link individually.
The reason I don't turn it off when placing the files is that I need it on for a pdf.
I need more information to solve the problem: a screenshot or detailed description of the error. Ideally, I'd like to get a sample file so I could test the script against it.
It's the minus at the end, right before the closing parens. If you check, you will find it's probably an en-dash — one of the features I actually like about the forum! Every two hyphens get converted into an en-dash. So in Javascript code, you need to change them back to 2 hyphens, like this:
j++
(Hah, I wasn't going to fall in the same trap Where I typed a + you need a -.)
Ah ha! Of course. I thought that en dash looked strange.
This still doesn't work for me, but I think it is because I am using placed PSD or PDF files (not INDD files).
What I'm hoping for is a way to toggle the setting of a particular layer on/off in all PDF/INDD/PSD/AI files that I have placed. For example, I might place 20 graphics that have a layer called "French" and when I run the script, I would want that layer to be turned on or off in all the images. Easy change to this script?
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();
}
}
The script is still beautified, but only on line 30. Right after the last i in the line that reads
for (i = links.length-1; i>=0; i–)
there should be two hyphens, not one single en-dash.
Hi Jongware, i'm a new user.
Your script is very intersting, maybe you can help me.
My problem is similar. I have a inDesign book and many levels for the language. Every time i have to make a pdf of the book i must open the book's files one by one and change the language layer. I have 9 languages ( "IT", "EN", "FR", "DE", "ES", "PT", "RU", "HU) and maybe in the future there will be others.
The question is, can you fit the posted script to solve my problem? I would like to change the language layer of the entire book without opening all the file one by one.
I tried also to modify your script… but, really, i'm not capable.
It would be very useful for me if anybody could help me.
Thanks, daPupe
PS. sorry for my english, it is not very well. i hopeyou understand my problem