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
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();
}
}
Copy link to clipboard
Copied
i know of one which only gets rid of invisible layers which can be found at:
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:
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
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
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();
}
}
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
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
Copy link to clipboard
Copied
The problem was a capital L in getElements()...
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?
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
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!
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
Copy link to clipboard
Copied
good to know, i'll keep that in mind. thanks again!