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

How to get all images in indesign CS5 with javascript?

Community Beginner ,
Jan 25, 2011 Jan 25, 2011

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
5.4K
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

Valorous Hero , 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

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

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

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

I want to delete all images in indesign,anyone can

give some example codes?

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

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/

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
Valorous Hero ,
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

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

Dear Kasyank,Marijan

Thanks for your help!

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

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

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

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 )

 

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

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

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 )

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

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

 

Regards,

-Sumit
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