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

How to get all images in indesign CS5 with javascript?

Community Beginner ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

Hi,everybody,

How to get all images in indesign CS5 with javascript?I want to delete them.

Anyone can give me some example codes?

Thanks,

Bridge

TOPICS
Scripting

Views

4.8K

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

Guru , Jan 25, 2011 Jan 25, 2011

var doc = app.activeDocument;
var graphics = doc.allGraphics;

for (var i = graphics.length-1; i >= 0; i--) {
     try {
          graphics.remove(); // delete only image
          // graphics.parent.remove(); // delete image and its containing frame
     }
     catch (err) {}
}

Note: Tested in CS3, Windows

Hope this helps.

Kasyan

Votes

Translate

Translate
Community Beginner ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

Did you try the "Move to Layer" script that's in Exchange (http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1697030)?

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 Beginner ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

I want to delete all images in indesign,anyone can

give some example codes?

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 ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

Hey!

This will remove all images from your InDesign document:

var myLinks = app.activeDocument.links.everyItem().parent;
for(var i = 0; i < myLinks.length; i++)
    myLinks.remove();

Hope that helps.

--

tomaxxi

http://indisnip.wordpress.com/

http://inditip.wordpress.com/

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
Guru ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

var doc = app.activeDocument;
var graphics = doc.allGraphics;

for (var i = graphics.length-1; i >= 0; i--) {
     try {
          graphics.remove(); // delete only image
          // graphics.parent.remove(); // delete image and its containing frame
     }
     catch (err) {}
}

Note: Tested in CS3, Windows

Hope this helps.

Kasyan

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 Beginner ,
Jan 26, 2011 Jan 26, 2011

Copy link to clipboard

Copied

Dear Kasyank,Marijan

Thanks for your help!

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
Engaged ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

You can also delete specific graphics.

var myGraphics = app.activeDocument.allGraphics; 

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

         if((myGraphics.imageTypeName == "PNG")||(myGraphics.imageTypeName == "JPEG")){

          myGraphics.parent.remove();

          }

}

Sumit

-Sumit

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
Engaged ,
Oct 31, 2021 Oct 31, 2021

Copy link to clipboard

Copied

Hi Kashyan,

 

I did not understand that why you use here loop becuase you are removing all graphics at once then why loop?

 

Regards,

-Sumit

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 ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

Hi Sumit,

allGraphics is an array and not a collection.

The alternative you might have thought of would be using the pageItems and the graphics collections:

app.documents[0].pageItems.everyItem().graphics.everyItem().remove();

But this would not catch graphics in nested structures like groups, graphic cells or even more complex structures like buttons or MSOs for example. And it would not remove the container frames. There simply is no parents collection with a method like remove().

 

The other alternative using the links collection of the document is also no candidate for everyItem().remove(). Method remove() is missing for link objects. Here again we need the parent of a particular link to remove one. Also: Not every link links to a graphic file. Not every graphic is placed and linked.

 

Regards,
Uwe Laubender

( ACP )

 

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
Engaged ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

Hi Laubender,

 

Thank you for your message. See below code from Kasyan.

 

var doc = app.activeDocument;
var graphics = doc.allGraphics;

for (var i = graphics.length-1; i >= 0; i--) {
     try {
          graphics.remove(); // delete only image
          // graphics.parent.remove(); // delete image and its containing frame
     }
     catch (err) {}
}

 //You can see above code array is not used like graphics[i].remove(). code is remove all the time graphics.remove().

 

Regards,

-Sumit

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 ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

That's an error in Kasyan's posted code and was caused by a bug when this old thread was moved to this new forum about two years ago. The code was damaged by moving the thread.

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

LATEST

Ok, now I understand. Thank you very much for the explanation.

 

Regards,

-Sumit

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