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

get graphic-paths

Engaged ,
Mar 07, 2019 Mar 07, 2019

Hi.

To check the deletable paths, I need to collect the contents of some documents. I'm only looking for graphic objects.

The following script works in principle (if I search the paths individually), only at one point the error message is output: "null is not an object".



var myDoc = app.activeDocument;

var myPaths = Array();

var eachGrafic = myDoc.allGraphics.length;

var myGraphics = myDoc.allGraphics;

for(i=0; i<eachGrafic; i++){

    if(app.activeDocument.allGraphics.itemLink.filePath != null) {

//~         app.select(app.activeDocument.allGraphics);

//~         alert(app.activeDocument.allGraphics.itemLink.filePath)

        myPaths.push(myGraphics.itemLink.filePath)

        }

    }

alert(myPaths);

There are no hidden objects or layers. What could be the reason?

TOPICS
Scripting
789
Translate
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 , Mar 07, 2019 Mar 07, 2019

Hi cmoke73 ,

there could be graphics in the document where no itemLink is there.

Pixels perhaps that are pasted from e.g. PhotoShop.

Screenshot from my German InDesign:

"Ebenen" means "Layers"

"Ebene 1" means "Layer 1"

"<eingefügte Grafik>" means "<pasted Graphic>"

"Verknüpfungen" means "Links"

PastedGraphic-No-ItemLink-1.PNG

In the sample document shown above there is one pasted bunch of pixels from PhotoShop.

allGraphics array length is 1.

app.documents[0].allGraphics[0].itemLink ; // Returns null

app.documents[0].allGraphics[0].itemLi

...
Translate
Community Expert ,
Mar 07, 2019 Mar 07, 2019

Hi,

Without seeing the document I am not sure why your code is raising an error.

Although you could use this as it should return all the graphics in the document.

var myGraphics = app.activeDocument.pages.everyItem().pageItems.everyItem().graphics.everyItem().getElements();

Feel free to post the document to a file sharing site and we can take a look at why your code is not working.

Regards

Malcolm

Translate
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
Engaged ,
Mar 07, 2019 Mar 07, 2019

Hi Malcolm!

Thank you for replying. Now I recognized the script is working with an other document, with even more content. So I have no idea why or why not. Unfortunately I cannot share the document. It´s from the company I´m working at and it is not allowed.

Translate
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 ,
Mar 07, 2019 Mar 07, 2019

Hi cmoke73 ,

there could be graphics in the document where no itemLink is there.

Pixels perhaps that are pasted from e.g. PhotoShop.

Screenshot from my German InDesign:

"Ebenen" means "Layers"

"Ebene 1" means "Layer 1"

"<eingefügte Grafik>" means "<pasted Graphic>"

"Verknüpfungen" means "Links"

PastedGraphic-No-ItemLink-1.PNG

In the sample document shown above there is one pasted bunch of pixels from PhotoShop.

allGraphics array length is 1.

app.documents[0].allGraphics[0].itemLink ; // Returns null

app.documents[0].allGraphics[0].itemLink.filePath ; // Throws an error: Null is not an object

So always check, if itemLink == null before going on with any property of itemLink.

Regards,
Uwe

Translate
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
Engaged ,
Mar 08, 2019 Mar 08, 2019

Hallo Uwe.

Danke für den Hinweis!

So I tried nearly the same to avoid the error:

if (app.documents[0].allGraphics[0].itemLink.filePath != null) {

...

}

But your hint was the salvation.

Thank you.

Translate
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 ,
Mar 08, 2019 Mar 08, 2019
LATEST

Nearly the same?

Hm. No. 🙂

Best,
Uwe

Translate
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