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

Script to hide layer named "Draft" in multiple files.

Explorer ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

new to scripting... please help! I have this script:

app.activeDocument.save();

var myWaterLayerName = "Draft";

try{app.activeDocument.layers.item(myWaterLayerName).visible = false;}

catch(_){alert("Can't find layer: " + myWaterLayerName);exit();};

that hides a layer in the active document. how can i modify to work on all open documents?

TOPICS
Scripting

Views

1.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 1 Correct answer

Community Expert , Sep 30, 2018 Sep 30, 2018

Hi Malcom,

you need no loop because you can work with the collection of documents:

app.documents.everyItem().layers.itemByName("Draft").visible = false;

This is working even if some of the documents do not contain a layer named "Draft".

getElements() will give you an array. Because of that you have to loop.

Regards,
Uwe

Votes

Translate

Translate
Community Expert ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

[ moved from InDesign  to InDesign Scripting  ]

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
Participant ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

Hello!

I am new at scripting as well, but I think I’ve come up with a solution for you. The script may take a while to run if you have a lot of documents open.

Try the code below.

  var myWaterLayerName = "Draft";

        for(myCounter = app.documents.length;

              myCounter > 0;

              myCounter--){

        try{

            app.documents.item(myCounter-1).layers.item(myWaterLayerName).visible = false;

            app.documents.item(myCounter-1).save();         

            }

        catch(_){alert("Can't find layer: " + myWaterLayerName);exit();};

    }

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 ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

Hi,

a similar but simpler script to do the job,

var toHideLayers = app.documents.everyItem().layers.itemByName("Draft").getElements();

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

{

    toHideLayers.visible = false;

}

This will get the layer called "Draft" from every open document.

Hope this helps.

Malcolm

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 ,
Sep 30, 2018 Sep 30, 2018

Copy link to clipboard

Copied

Hi Malcom,

you need no loop because you can work with the collection of documents:

app.documents.everyItem().layers.itemByName("Draft").visible = false;

This is working even if some of the documents do not contain a layer named "Draft".

getElements() will give you an array. Because of that you have to loop.

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 ,
Oct 01, 2018 Oct 01, 2018

Copy link to clipboard

Copied

thanks! this is working perfectly! Much 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
Community Expert ,
Sep 30, 2018 Sep 30, 2018

Copy link to clipboard

Copied

Of course, don't know how I didn't see that.

Regards

Malcolm

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 ,
Oct 01, 2018 Oct 01, 2018

Copy link to clipboard

Copied

LATEST

thanks everyone for the 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