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

list images for a visible layers only

Enthusiast ,
Apr 25, 2013 Apr 25, 2013

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

TOPICS
Scripting

Views

931

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

Advisor , Apr 25, 2013 Apr 25, 2013

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++) {

                         

...

Votes

Translate

Translate
Explorer ,
Apr 25, 2013 Apr 25, 2013

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.visible == true)

    {

        for(i=0; i<myGraphics.length; i++)

        {

            if(myGraphics.itemLayer == myLayer)         // Check the item is in visible layer

                 alert(myGraphics.itemLink.name)

            }

        }

    }

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
Enthusiast ,
Apr 25, 2013 Apr 25, 2013

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

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
Enthusiast ,
Apr 25, 2013 Apr 25, 2013

Copy link to clipboard

Copied

Hi,

a layer's got a own property allGraphics

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
Advisor ,
Apr 25, 2013 Apr 25, 2013

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"));

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 ,
Apr 25, 2013 Apr 25, 2013

Copy link to clipboard

Copied

Hi Vamitul

Thankyou for showing me the easiest way.

doc.layers.allGraphics

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
Advisor ,
Apr 26, 2013 Apr 26, 2013

Copy link to clipboard

Copied

LATEST

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:

http://www.indiscripts.com/post/2010/07/on-everyitem-part-2

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