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

Delete unused layer..?

Guest
Nov 02, 2011 Nov 02, 2011

Copy link to clipboard

Copied

Hi Everyone!,

I am new baby to indesign scripting and anyone to help me find that below indesign script.

How do i delete unused layer in indesign CS4? and how do know linked image mode like CMYK, RGB, LAB.

Thanks in Advance.

- yajiv

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

LEGEND , Nov 03, 2011 Nov 03, 2011

This should remove empty layers:

var layers = app.documents[0].layers.everyItem().getElements();

for(var i=layers.length-1;i>=0;i--){

  if(layers.pageItems.length==0){

    layers.remove();

  }

}

Votes

Translate

Translate
Community Expert ,
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

i know of one which only gets rid of invisible layers which can be found at:

http://objectmix.com/adobe-indesign/239660-how-delete-invisible-layers-inindesign-cs2-file-using-jav...

alternatively, google the script "inwash.jsx" by vitaly batushev

in terms of finding out if a linked image is CMYK, RGB, LAB etc, this can be done from the links panel itself from CS4 and up. If you can't see it at the moment, go to the panel options within the links panel and select  the following:

Screen shot 2011-11-03 at 10.03.32 PM.png

this is only really useful for rasters such as tiffs, jpgs etc. it won't advise if a PDF contains RGB, CMYK etc for example.

i know it's not what the OP was hoping for, but hope it helps

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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
Guest
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

Hi cdflash!,

Thanks for your kind reply. Actualy i need to delete unused layer (ie. There is no link image include in that layer).

I'm try to write script but i can't. I know that Color Space in Pannel option. Some time i forget saw that option.

that's why i need that script.

-yajiv

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
LEGEND ,
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

This should remove empty layers:

var layers = app.documents[0].layers.everyItem().getElements();

for(var i=layers.length-1;i>=0;i--){

  if(layers.pageItems.length==0){

    layers.remove();

  }

}

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
LEGEND ,
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

place a single image in an empty doc, and this will give you the color space:

alert (app.documents[0].pageItems[0].images[0].space);

Harbs

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
Guest
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

Hi Harbs!

Thanks for you reply.

I used your above script, slightlty modify and Its work fine.

Here th modify code...

var layers = app.activeDocument.layers.everyItem().getElements();

for(var i=layers.length-1;i>=0;i--){

  if(layers.pageItems.length==0){

    layers.remove();

  }

}

Thank you very much....

-yajiv

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
LEGEND ,
Nov 03, 2011 Nov 03, 2011

Copy link to clipboard

Copied

The problem was a capital L in getElements()...

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hi all, the solution here works with the active doc only.

var layers = app.activeDocument.layers.everyItem().getElements();

for(var i=layers.length-1;i>=0;i--){

  if(layers.pageItems.length==0){

    layers.remove();

  }

}

How do I modify this so that it delete all unused layers in all open document? Not only in the active doc?

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hi Brian,

important note: Your method does not see into master spreads.

And—I hope this is obvious—guides will not count as page items.

To access all open documents, loop all documents.

So you need two loops, one nested in the other.

var allOpenDocs = app.documents.everyItem().getElements();

for(var n=0;n<allOpenDocs.length;n++)

{

    var currentDoc = allOpenDocs;

    var currentLayers = currentDoc.layers.everyItem().getElements();

    for(var i=currentLayers.length-1;i>=0;i--)

    {

          if(currentLayers.pageItems.length == 0)

          { currentLayers.remove() }

    }

};

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

thank you Uwe!

I would hug you if i could.

i knew it takes 2 loops, but i am not js savy enough to make it work. Spent couple of hours on this.

forever grateful!

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

And amother note:
You'll get into trouble—error message that stops your script—if it comes accross a document where all contents is on masters.

Why? Because you cannot remove all layers of an empty document. One layer has to remain.

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

LATEST

good to know, i'll keep that in mind. thanks again!

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