Reply To: Automate change object layer option

Home Page / Forums / General InDesign Topics (CLOSED) / Automate change object layer option / Reply To: Automate change object layer option

#14366657
Theo de Klerk
Participant

I solved my problem – partly but enough for me. A little adjustment to the LayerVisibility script worked for me.
Just go to InDesign and set a particular layer current. Then run the script that you filled with the two PhotoShop layers that should be present in all images (ignoring any other that might be there) and run it. That script works fine with a little more handwork than I hoped for, but it beats manually modifying each InDesign Object Layer Option.

Main();

//
// set layers on/off in an image or images on one InDesign page
//
function Main()
{
var page, placedFile, links, layer, i, j, k, doc;
var doc = app.activeDocument;
var curLayer = doc.activeLayer;
var pages = doc.pages

var checklist = [];

var PSlayernames = [ “extreme”, “subtle” ];

/* ——————————————————————————————————-
ABOVE IS WHERE YOU ALTER THE LAYER NAMES:
After the words “var layernames” there’s an opening square bracket , then some sets of text enclosed in quotes sperated by commas, and at the end, a closing square bracket.
Delete all of the text and the commas separating it, and in its place put in any layers that you want.
For example: If you have three layers, ‘red’, ‘green’ and ‘silver’, then in the brackets put in each layer enclosed in quotes and seperated by a comma, as such: [“red”, “green”, “silver”].
Make sure they are all double-quotes, not single quotes, and make sure they are ‘straight’ quotes not ‘smart’ quotes.
To ensure that it’s properly formatted, only edit the script in a generic text editor (such as Notepad on Windows, or Text Wrangler on Mac).
DO NOT use a word-proccesing program such as MS Word or InDesign, as that will add formatting to the script and it will not work properly.
——————————————————————————————————- */

var ilDialog = app.dialogs.add({name:”Image Layers on/off on ” + curLayer.name, canCancel:true});
with (ilDialog)
{
with(dialogColumns.add())
{
with(dialogRows.add())
{
staticTexts.add ({staticLabel:”Check image layers to show, uncheck to hide on “+ curLayer.name});
for (i=0; i < PSlayernames.length; i++)
{
with(dialogRows.add())
checklist.push (checkboxControls.add({staticLabel:PSlayernames[i], checkedState:false}));
}
}
}
}
var numChanges = 0;
var imageChange;
if (ilDialog.show() == true)
{
// find all images by their links and process them one by one
links = doc.links;
for (i = links.length-1; i>=0; i- -)
{
// get the file info from the link: stored as “parent” of the link
placedFile = links[i].parent;

// file must be an image, not null and made by Photoshop
if (placedFile.constructor.name == “Image” && placedFile.itemLink != null && placedFile.itemLink.linkType == “Photoshop” )
{
imageChange = false;
if (placedFile.itemLayer == curLayer)
{
// check layers names defined for change and see if this name corresponds witrh the Photoshop file layer
for (k=0; k < PSlayernames.length; k++)
{
// find Photoshop layer byt that name in the image. If it does not exist, the layer will be invalid
layer = links[i].parent.graphicLayerOptions.graphicLayers.item(PSlayernames[k]);

// if layer exists, and if its visibility is not according to checklist in dialogbox, change it to match set visibility (if correct, don’t bother)
if (layer.isValid && layer.currentVisibility != checklist[k].checkedState)
{
layer.currentVisibility = checklist[k].checkedState;
imageChange = true;
}
}
// count the number of changes made
if (imageChange)
numChanges++;
}
}
}
alert(“Done, made changes in “+numChanges+” images”);
} else
{
ilDialog.destroy();
}
}

This article was last modified on June 11, 2022

Comments (0)

Loading comments...