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

Layer Visibility Overrides for all Instances of a linked file

Explorer ,
Jul 15, 2019 Jul 15, 2019

Copy link to clipboard

Copied

Is there a way to remove “layer visibility overrides” from all instances of a linked Illustrator file in InDesign? Example: I have 25 instances of an illustrator file and I want to change all of the instances to “use PDF layer visibility” without changing each manually.  Or alternatively, select all instances of a linked file and set all the visible layers for all instances in one place. 

TOPICS
Scripting

Views

7.3K

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

correct answers 2 Correct answers

Contributor , Mar 04, 2020 Mar 04, 2020

Hi,

here's a version with a modified interface with "real" checkboxes. The graphic layers will now be listed on several pages in the interface. Currently 10 layers per page will be shown. If you want a different number per page, change the value of the variable layersPerPage.

Edit: I wrote this on a Windows 10 notebook with ID 14.0.3 so I don't know if there will be problems with the latest ID version or Mac OS.

sample.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

#targetengine "batchLayerVisibility"

var graphicInstances = null
...

Votes

Translate

Translate
Contributor , Mar 05, 2020 Mar 05, 2020

Well,

just for the heck of it I added a third button that inverts the selection.

blv1-4.png

#targetengine "batchLayerVisibility"

var graphicInstances = null, instancesCount = null, checkboxes = null, ui_layerList = null, sel = null, pbarWindow = null, pbar_layer, pbarText;

main();

function main() {

	proceed = false;

	if (app.selection.length == 0) {
		alert("Nothing selected.");
		exit();
	}

	sel = app.selection[0];
	
	sel = sel instanceof PDF ? sel : sel.graphics[0];
	try {
		var test = sel.graphicLay
...

Votes

Translate

Translate
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

Try relinking it along with show options.

However, if you want different options for each, you'd probably need a script.

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
Explorer ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

The issue with that is I need to maintain specific artboard / page links,

if I go that route I think it defaults to the 1st artboard in all

instances.

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 ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

Right…which is why I pointed that out.

You might want to pop over to the scripting forum and see if anyone can help.

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
Adobe Employee ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

Hi Aaron,

Thanks for reaching out. As Bob mentioned, this might be possible through scripting. Hence moving the discussion to InDesign Scripting community.

Regards,

Srishti

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
Explorer ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Does anyone know how to script something like this?

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
Contributor ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi,

you could try this one

main();

function main() {

var sel = app.selection[0];

if (!sel) {

alert("Nothing selected.");

exit();

}

try {

var test = sel.graphicLayerOptions.graphicLayers;

if (test.length == 0) {

alert("Selected object not supported.");

exit();

}

} catch (err) {

alert("Please select an .AI image with the white selection tool or click in the links panel on the graphic.");

exit();

}

var graphicFile = sel.itemLink.filePath;

instances = new Array();

var allGraphics= app.activeDocument.allGraphics;

// collect instances

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath == graphicFile) {

instances.push(allGraphics);

}

}

makeWindow();

}

function makeWindow() {

var w = new Window("dialog", "Batch Layer Visibility");

w.alignChildren = ["fill", "fill"];

checkboxes = new Array();

var panel = w.add("panel", undefined, "Layer Visibility");

panel.alignChildren = ["fill", "fill"];

for (var i = 0; i < instances[0].graphicLayerOptions.graphicLayers.length; i++) {

checkboxes = panel.add("checkbox");

checkboxes.text = instances[0].graphicLayerOptions.graphicLayers.name;

checkboxes.value = instances[0].graphicLayerOptions.graphicLayers.currentVisibility;

}

update_options = new Array();

updateOptionsPanel = w.add("panel", undefined, "Link Update Options");

updateOptionsPanel.alignChildren = ["fill", "fill"];

update_options[0] = updateOptionsPanel.add("radiobutton", undefined, "PDF Visibility");

update_options[1] = updateOptionsPanel.add("radiobutton", undefined, "Custom Visibility");

if (app.selection[0].graphicLayerOptions.updateLinkOption.toString() == "APPLICATION_SETTINGS") {

update_options[0].value = true;

} else {update_options[1].value = true;}

var btnGrp = w.add("group");

btnGrp.orientation = "row";

var closeBtn = btnGrp.add("button", undefined, "Exit");

closeBtn.onClick = function () {

proceed = false;

w.close();

exit();

}

var exeBtn = btnGrp.add("button", undefined, "OK", {name: "ok"});

exeBtn.onClick = function() {

proceed = true;

w.close();

}

w.show();

}

if (proceed == true) {

app.doScript(setVisibility, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.entireScript, "Batch Layer Visibility");

}

function setVisibility() {

var graphicFile = app.selection[0].itemLink.filePath;

for (var c = 0; c < checkboxes.length; c++) {

var allGraphics= app.activeDocument.allGraphics;

// collect instances

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath == graphicFile) {

allGraphics.graphicLayerOptions.graphicLayers.currentVisibility = checkboxes.value;

}

}

}

allGraphics = app.activeDocument.allGraphics;

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath ==graphicFile) {

if (updateOptionSel = updateOptionsPanel.children[0].value == true) {

allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.APPLICATION_SETTINGS;

} else {

allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.KEEP_OVERRIDES;

}

}

}

}

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 ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Hi crazyPanda ,

if something goes wrong with currentVisibility and the loop through the allGraphics array read into this here:

Re: Place specific pdf layer into indesign with javascript

Note: Changing the value of currentVisibility of graphicLayer will change the ID of the placed graphic.

Old bug.

Regards,
Uwe

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
Contributor ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Hi Laubender,

I actually ran into this problem when I wrote that script yesterday. I almost would have given up because of that. But I guess the work around for this script will work just fine.

It gets all instances of the graphic based on its filepath. Then it changes the visibility of the first layer of the first instance, moves on to the second instance and changes the visibility of the first layer, moves on to the third instance ... and so on. After processing the last instance it starts all over again: collect all instances again, change the visibility of the second layer of the first instance, moves on the the second instance... and so on.

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 ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

crazyPanda  wrote

Hi Laubender ,

I actually ran into this problem when I wrote that script yesterday. I almost would have given up because of that. But I guess the work around for this script will work just fine. …

Hi

I did a bug report on this at Adobe InDesign UserVoice:

Scripting | graphicLayerOptions : Changing visibility of graphicLayer will change ID number of place...

If you did not do it, please vote for fixing the bug 🙂

Regards,
Uwe

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
Explorer ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Hi crazyPanda​,

Would it be possible to add a vertical scroll bar to the dialogue box? In some cases I have more layers than are fitting on the screen...

Also, it seems to be working fine.. but is there something that Labender referenced that needs to be addressed? I am not really following what exactly the issues is... 

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 ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Hi aaronf31067511 ,

read into my bug report to understand a bit of the issue and do some tests with:

1. Placed InDesign Page with some layers

2. Placed PDF page with some layers

3. Placed AI artboard with some layers

4. Placed PSD with some layers

crazyPanda did a workaround of the bug. So no worry.

Regards,
Uwe

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
Contributor ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

aaronf31067511

Regarding a scrollbar I'll try to find a solution when I'm back home.

Regarding that bug there's nothing to worry about.

Laubender

I've upvoted that bug report.

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
Explorer ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

@crazyPanda Thank you so much!!

If it helps.. I have seen it approached like the attached script for Illustrator with tabbed panels (rather than a scroll bar, although not as clean).

Laubender​  I have also upvoted. Thank you for the guidance here. 

//

//     LAYER RENAMER

//    Simple way to rename multiple layers

//     Including addition of prefix's and suffix's.

//

//    Author: Qwertyfly

//    Contact: tristan@qwertyfly.com

//

//    Version 1.001 - 02/3/17

//

//     Change Log:

//     V1.001 - large overhaul

//                     Including addition of Pages to deal with large layer counts

//                     and selectall checkboxes.

//                     Code is still a mess, needs to be cleaned up...,

//    

//

// All code within this script is the property of Tristan O'Brien.

// This script is free for personal use

// Permission is required prior to any commercial application.

//

//  any suggestions? drop me a line...

//

// -------- User Variable ----------

var numberOfLayersPerPage = 10;

//---------------------------------------

layerRenamer();

function layerRenamer(){

    var doc = app.activeDocument, lays = [];

   

    for(var i = 0; i < doc.layers.length; i++){ 

        lays.push(doc.layers.name); 

    }

    var layerQty = lays.length;

    var currentPage = 1;

    var rangeS = 1;

    var rangeE = 10;

    var pageQty = Math.ceil(layerQty/numberOfLayersPerPage);

    var page = [];

   

    var w = new Window('dialog',"Layer Name Editor"); 

    var list = w.add('group'); 

    list.orientation = "Column"; 

   

    var s, n, p, head;

    var  pre = [], nam = [], suf = [];

   

    var tabs = list.add ("tabbedpanel");

    tabs.alignChildren = ["fill", "fill"];

    tabs.preferredSize = [280,300];

   

    for(var j = 0; j < pageQty;j++){

        if(currentPage === pageQty){

            rangeE = layerQty;

        }

        page[currentPage] = tabs.add('tab',undefined,rangeS + " - " + rangeE);

       

//now add lines.

        addHead(page[currentPage]);

        for(var i = rangeS-1; i < rangeE; i++){ 

            newLine(i,"item" + i,page[currentPage]); 

        }

   

        rangeS = rangeS + 10;

        rangeE = rangeE + 10;

        currentPage++

    }

   

   

   

function addHead(currentPage){ 

    head = currentPage.add('group'); 

    head.alignment = "left"; 

    p = head.add('statictext', undefined, "Prefix"); 

    n = head.add('statictext', [0,0,165,20], "            Layer Name"); 

    s = head.add('statictext', undefined, "Suffix"); 

}   

   

   

     

    function newLine(num,item,currentPage){ 

        item = currentPage.add('group'); 

        item.alignment = "left"; 

        pre[num] = item.add('checkbox', undefined,""); 

        nam[num] = item.add('edittext', [0,0,200,20], lays); 

        nam[num].characters = 50; 

        suf[num] = item.add('checkbox', undefined, ""); 

    } 

    selectAll();

    function selectAll(){

         var selAll =  list.add('group');

         selAll.alignment = ["fill","fill"];

         var preAll = selAll.add('checkbox',undefined,"");

         var AllText = selAll.add('statictext',[0,0,230,20],"       <-------      Select All      ------->");

         var postAll = selAll.add('checkbox',undefined,"");

         preAll.onClick = function(){checkAll(pre,preAll.value)};

         postAll.onClick = function(){checkAll(suf,postAll.value)};

    }

    function checkAll(checkboxArray,Value){

        var checked = false;

        if(Value === true){

            checked = true;

        }

        for(var k = 0;k < checkboxArray.length ; k++){

            checkboxArray.value = checked;

        }

    }

    var sep1 = list.add("panel"); 

    sep1.alignment = ["fill","fill"]; 

    sep1.minimumSize.height = sep1.maximumSize.height = 2; 

    var prefixt = list.add('statictext', undefined, "Prefix to add to checked layers"); 

    var prefix = list.add('edittext', [0,0,250,20], ""); 

    var sep2 = list.add("panel"); 

    sep2.alignment = ["fill","fill"]; 

    sep2.minimumSize.height = sep2.maximumSize.height = 2; 

    var prefixt = list.add('statictext', undefined, "Suffix to add to checked layers"); 

    var suffix = list.add('edittext', [0,0,250,20], ""); 

    var sep3 = list.add("panel"); 

    sep3.alignment = ["fill","fill"]; 

    sep3.minimumSize.height = sep3.maximumSize.height = 2; 

    var ButtonGroup = w.add("group"); 

      ButtonGroup.margins = [0,-10,0,-8]; 

      ButtonGroup.alignment = "right"; 

      var go = ButtonGroup.add ("button", undefined, "OK"); 

      var stop = ButtonGroup.add ("button", undefined, "Cancel"); 

      stop.onClick = function(){ 

      w.close(); 

      } 

        go.onClick = function(){ 

            var validatePre = false, validateSuf = false, validateMessage = ""; 

            for(var i = 0; i < lays.length; i++){ 

                if(pre.value == true && prefix.text == ""){validatePre = true} 

                if(suf.value == true && suffix.text == ""){validateSuf = true} 

            } 

            if(validatePre == true){validateMessage = "Layers have been marked for Prefix, but no Prefix entered\n"} 

            if(validateSuf == true){validateMessage = validateMessage + "Layers have been marked for Suffix, but no Suffix entered"} 

            if(validateMessage != ""){ 

                alert(validateMessage); 

            }else{ 

                w.close(); 

                goTime(); 

            } 

      } 

    w.show();

     

     

    function goTime(){ 

        for(var i = 0; i < lays.length; i++){ 

            var na = nam.text; 

            var pr = ""; 

            var su = ""; 

            if(pre.value == true){pr = prefix.text + " - "} 

            if(suf.value == true){su = " - " + suffix.text} 

            doc.layers.name = pr + na + su; 

        } 

    }

}

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
Contributor ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

So this is what it looks like now: All layers are now listed in a scrollable list.

scrollable list.png

While trying to change to visibility of more than one layer it occured to me that a progressbar might be a nice addition because I couldn't tell whether Indesign had frozen or if it was still running that script.

progressbar.png

So here's the new version:

#targetengine batchLayerVisibility

main();

function main() {

proceed = false;

if (app.selection.length == 0) {

alert("Nothing selected.");

exit();

}

var sel = app.selection[0];

try {

var test = sel.graphicLayerOptions.graphicLayers;

if (test.length == 0) {

alert("Selected object not supported.");

exit();

}

} catch (err) {

alert("Please select an .AI image with the white selection tool or click in the links panel on the graphic.");

exit();

}

var graphicFile = sel.itemLink.filePath;

instances = new Array();

var allGraphics= app.activeDocument.allGraphics;

// collect instances

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath == graphicFile) {

instances.push(allGraphics);

}

}

instancesCount = instances.length;

makeWindow();

}

function makeWindow() {

var w = new Window("dialog", "Batch Layer Visibility 1.1");

w.alignChildren = ["fill", "fill"];

checkboxes = new Array();

var panel = w.add("panel", undefined, "Layer Visibility");

panel.alignChildren = ["fill", "fill"];

layerList = panel.add("listbox", [0, 0, 400, 500], undefined, {multiselect: false, scrolling: true});

for (var i = 0; i < instances[0].graphicLayerOptions.graphicLayers.length; i++) {

var tempItem = layerList.add("item", instances[0].graphicLayerOptions.graphicLayers.name);

tempItem.checked = instances[0].graphicLayerOptions.graphicLayers.currentVisibility;

//tempItem.onClick = function () {alert();}

}

layerList.onChange =setCheckboxStatus; // call function setCheckboxStatus

checkboxes = layerList.items;

update_options = new Array();

updateOptionsPanel = w.add("panel", undefined, "Link Update Options");

updateOptionsPanel.alignChildren = ["fill", "fill"];

update_options[0] = updateOptionsPanel.add("radiobutton", undefined, "PDF Visibility");

update_options[1] = updateOptionsPanel.add("radiobutton", undefined, "Custom Visibility");

if (app.selection[0].graphicLayerOptions.updateLinkOption.toString() == "APPLICATION_SETTINGS") {

update_options[0].value = true;

} else {update_options[1].value = true;}

var btnGrp = w.add("group");

btnGrp.orientation = "row";

var closeBtn = btnGrp.add("button", undefined, "Exit");

closeBtn.onClick = function () {

proceed = false;

w.close();

exit();

}

var exeBtn = btnGrp.add("button", undefined, "OK", {name: "ok"});

exeBtn.onClick = function() {

proceed = true;

w.close();

}

w.show();

}

if (proceed == true) {

app.doScript(setVisibility, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.entireScript, "Batch Layer Visibility");

}

function setVisibility() {

pbar();

var graphicFile = app.selection[0].itemLink.filePath;

for (var c = 0; c < checkboxes.length; c++) {

var allGraphics= app.activeDocument.allGraphics;

// seek instances and change visibility

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath == graphicFile) {

//pbar_instance.value++;

allGraphics.graphicLayerOptions.graphicLayers.currentVisibility = checkboxes.checked;

pbar_layer.value++;

}

}

}

allGraphics = app.activeDocument.allGraphics;

// set link update option

for (var i = 0; i < allGraphics.length; i++) {

if (allGraphics.itemLink.filePath ==graphicFile) {

if (updateOptionSel = updateOptionsPanel.children[0].value == true) {

allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.APPLICATION_SETTINGS;

} else {

allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.KEEP_OVERRIDES;

}

pbar_layer.value++;

}

}

pbarWindow.close();

}

function setCheckboxStatus() {

if (layerList.selection.checked == true) {

layerList.selection.checked = false;

} else {layerList.selection.checked = true;}

var tempSel = layerList.selection;

layerList.selection = null;

}

function pbar () {

pbarWindow = new Window ("palette", "Processing ...", undefined);

pbarPanel = pbarWindow.add("panel");

//pbarPanel.add("statictext", undefined, "Instances");

//pbar_instance = pbarPanel.add("progressbar", undefined, 0, instancesCount);

pbarPanel.add("statictext", undefined, "Progress:");

pbar_layer = pbarPanel.add("progressbar", undefined, 0, (instancesCount * checkboxes.length) + instancesCount);

pbar_layer.preferredSize.width = 200;

pbarWindow.show();

}

If you want to modify the size of the window change the third and forth number within the brackets in line 55:

layerList = panel.add("listbox", [0, 0, 400, 500], undefined, {multiselect: false, scrolling: true});

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
Explorer ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Wow this is perfect!

One little bug.. If you scroll down to the bottom of the list then scroll back up, the layers that were beyond the scroll window lose the check box. They come back if you click on the layer so it doesn't effect the function.. just a little bug.  See layers at top, these were beyond the scroll window.

Screen Shot 2019-07-25 at 3.16.18 PM.png

I can't thank you enough! This will save me hours of work!

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
Contributor ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Hi aaronf31067511​,

I assume you work on a Mac? The script window is programmed in ScriptUI. From my experience such interfaces work fine on Windows but on Mac sometimes they seem buggy.

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
Explorer ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

ahhh.. yes, on a mac (code pasted into Adobe ExtendScript Toolkit).

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
Explorer ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

@crazyPanda

I'm not sure what happened but I started getting an error (I have not updated InDesign so not sure what is going on). Are you able to help, please please

Screen Shot 2019-08-12 at 11.24.17 AM.png

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 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Hi aaronf31067511 ,

are there some graphics that are not placed and linked?

Maybe copied and pasted from PhotoShop directly?

Or are there some placed graphics that were embedded into the InDesign document?

Regards,
Uwe

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
Explorer ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Hi Laubender​,

Nope, this is a placed Illustrator file... I have tried the script on a few different files with the same error result

Screen Shot 2019-08-12 at 11.39.42 AM.png

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
Contributor ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

Hi,

I can only assume that there is a graphic in the document that is neither linked nor embedded. We had a similiar problem with a different script that we use at work.

I modified the script so that it will ignore these graphics by adding the line

if (allGraphics.itemLink == null) {continue;}

#targetengine batchLayerVisibility

main();

function main() {

    proceed = false;

  

    if (app.selection.length == 0) {

        alert("Nothing selected.");

        exit();

    }

    var sel = app.selection[0];

  

    try {

        var test = sel.graphicLayerOptions.graphicLayers;

        if (test.length == 0) {

            alert("Selected object not supported.");

            exit();

        }

        } catch (err) {

            alert("Please select an .AI image with the white selection tool or click in the links panel on the graphic.");

            exit();

        }

  

    var graphicFile = sel.itemLink.filePath;

    instances = new Array();

    var allGraphics= app.activeDocument.allGraphics;

  

    // collect instances

    for (var i = 0; i < allGraphics.length; i++) {

        if (allGraphics.itemLink == null) {continue;}

        if (allGraphics.itemLink.filePath == graphicFile) {

            instances.push(allGraphics);

        }

    }

    instancesCount = instances.length;

  

    makeWindow();

}

function makeWindow() {

    var w = new Window("dialog", "Batch Layer Visibility 1.2");

    w.alignChildren = ["fill", "fill"];

    checkboxes = new Array();

  

    var panel = w.add("panel", undefined, "Layer Visibility");

    panel.alignChildren = ["fill", "fill"];

  

    layerList = panel.add("listbox", [0, 0, 400, 500], undefined, {multiselect: false, scrolling: true});

  

    for (var i = 0; i < instances[0].graphicLayerOptions.graphicLayers.length; i++) {

        var tempItem = layerList.add("item", instances[0].graphicLayerOptions.graphicLayers.name);

        tempItem.checked = instances[0].graphicLayerOptions.graphicLayers.currentVisibility;

        //tempItem.onClick = function () {alert();}

    }

    layerList.onChange =setCheckboxStatus; // call function setCheckboxStatus

  

    checkboxes = layerList.items;

  

    update_options = new Array();

  

    updateOptionsPanel = w.add("panel", undefined, "Link Update Options");

    updateOptionsPanel.alignChildren = ["fill", "fill"];

    update_options[0] = updateOptionsPanel.add("radiobutton", undefined, "PDF Visibility");

    update_options[1] = updateOptionsPanel.add("radiobutton", undefined, "Custom Visibility");

  

    if (app.selection[0].graphicLayerOptions.updateLinkOption.toString() == "APPLICATION_SETTINGS") {

        update_options[0].value = true;

    } else {update_options[1].value = true;}

  

    var btnGrp = w.add("group");

    btnGrp.orientation = "row";

  

    var closeBtn = btnGrp.add("button", undefined, "Exit");

    closeBtn.onClick = function () {

        proceed = false;

        w.close();

        exit();

    }

  

    var exeBtn = btnGrp.add("button", undefined, "OK", {name: "ok"});

    exeBtn.onClick = function() {

        proceed = true;

        w.close();

    }

  

    w.show();

}

if (proceed == true) {

    app.doScript(setVisibility, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.entireScript, "Batch Layer Visibility");

}

function setVisibility() {

    pbar();

  

    var graphicFile = app.selection[0].itemLink.filePath;

  

    for (var c = 0; c < checkboxes.length; c++) {

      

        var allGraphics= app.activeDocument.allGraphics;

      

        // seek instances and change visibility

        for (var i = 0; i < allGraphics.length; i++) {

            if (allGraphics.itemLink == null) {continue;}

            if (allGraphics.itemLink.filePath == graphicFile) {

              

                //pbar_instance.value++;

              

                allGraphics.graphicLayerOptions.graphicLayers.currentVisibility = checkboxes.checked;

              

                pbar_layer.value++;

            }

        }

    }

    allGraphics = app.activeDocument.allGraphics;

  

    // set link update option

    for (var i = 0; i < allGraphics.length; i++) {

        if (allGraphics.itemLink == null) {continue;}

        if (allGraphics.itemLink.filePath ==graphicFile) {

            if (updateOptionSel = updateOptionsPanel.children[0].value == true) {

                allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.APPLICATION_SETTINGS;

            } else {

                allGraphics.graphicLayerOptions.updateLinkOption = UpdateLinkOptions.KEEP_OVERRIDES;

            }

            pbar_layer.value++;

        }

    }

  

    pbarWindow.close();

  

}

function setCheckboxStatus() {

  

    if (layerList.selection.checked == true) {

        layerList.selection.checked = false;

    } else {layerList.selection.checked = true;}

    var tempSel = layerList.selection;

    layerList.selection = null;

}

function pbar () {

    pbarWindow = new Window ("palette", "Processing ...", undefined);

    pbarPanel = pbarWindow.add("panel");

  

    //pbarPanel.add("statictext", undefined, "Instances");

    //pbar_instance = pbarPanel.add("progressbar", undefined, 0, instancesCount);

  

    pbarPanel.add("statictext", undefined, "Progress:");

    pbar_layer = pbarPanel.add("progressbar", undefined, 0, (instancesCount * checkboxes.length) + instancesCount);

    pbar_layer.preferredSize.width = 200;

  

    pbarWindow.show();

  

}

Regards

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
Explorer ,
Aug 13, 2019 Aug 13, 2019

Copy link to clipboard

Copied

crazyPanda You are a mad scientist genius!!! Thank you!! 

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
Explorer ,
Feb 05, 2020 Feb 05, 2020

Copy link to clipboard

Copied

@crazyPanda

The script seems to have broken with upgrade to InDesign 2020... Any thoughts on how to fix? This script has become my go-to tool!! Help would be incredibly appreciated! 

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
Explorer ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Oh my gosh! Thank you!!!! I Have been trying to figure this out for months!!!! I think this works... You rock!

@laubender, I am not really too familiar with javascript (just learning). Is this something that I need to fix within @crazypanda 's script?

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