Copy link to clipboard
Copied
Hi,
I need images name for the layers visible is "true "only.
i.e., document contains 10 images, but the conditions is (layers visible = true) then document images is 7.
Trying Code:
var myDoc = app.activeDocument
var myGraphics = app.activeDocument.allGraphics
alert("docMyGraphics " + myGraphics.length)
var myLayer = app.activeDocument.layers.everyItem().getElements()
for(k=0; k<myLayer.length; k++)
{
if(myLayer
.visible == true) {
for(i=0; i<myGraphics.length; i++)
{
alert(myGraphics.itemLink.name)
}
}
}
Could anyone rewrite my code and give solution.
Plz it is very urgent.....
Thanks
Beginner
Hey Beginner, hey Suresh.
http://jongware.mit.edu/idcs5/pc_Layer.html
Each layer has it's own "allGraphics property, so a nicer way of doing is to use that:
...var doc = app.activeDocument;
var myLinks = [];
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers.visible) {
myLinks.push("Layer "+i+"("+doc.layers.name+"):")
var layerGraph = doc.layers.allGraphics;
for (var j = 0; j < layerGraph.length; j++) {
Copy link to clipboard
Copied
Hi
Try this:
var myDoc = app.activeDocument
var myGraphics = app.activeDocument.allGraphics
alert("docMyGraphics " + myGraphics.length)
var myLayer = app.activeDocument.layers.everyItem().getElements()
for(k=0; k<myLayer.length; k++)
{
if(myLayer
{
for(i=0; i<myGraphics.length; i++)
{
if(myGraphics.itemLayer == myLayer
alert(myGraphics.itemLink.name)
}
}
}
Copy link to clipboard
Copied
Hi Selvaraj,
Thanks for your quick response.....
Its working fine. I have given points as a helpful answer to you.
Thanks
Beginner
Copy link to clipboard
Copied
Hi,
a layer's got a own property allGraphics
Copy link to clipboard
Copied
Hey Beginner, hey Suresh.
http://jongware.mit.edu/idcs5/pc_Layer.html
Each layer has it's own "allGraphics property, so a nicer way of doing is to use that:
var doc = app.activeDocument;
var myLinks = [];
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers.visible) {
myLinks.push("Layer "+i+"("+doc.layers.name+"):")
var layerGraph = doc.layers.allGraphics;
for (var j = 0; j < layerGraph.length; j++) {
try { // not all graphics have a itemLink, for example the embedded ones
myLinks.push(layerGraph
.itemLink.name); } catch (e) {
myLinks.push("Error: Graphic " + j + " on layer " + i + " might be embedded");
}
}
}
}
alert (myLinks.join("\r"));
Copy link to clipboard
Copied
Hi Vamitul
Thankyou for showing me the easiest way.
doc.layers.allGraphics
Copy link to clipboard
Copied
one caveat: allGraphic, no matter weather it's on layer or doc (and as a matter of fact every property that starts with "all" - allParagraphStyles, allPageItems etc etc) returns a array, not a collection, so you can't use all the cool stuff (like everyItem) on it.
Marc has some excelent stuff here: