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
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
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)?
Copy link to clipboard
Copied
I want to delete all images in indesign,anyone can
give some example codes?
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/
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
Copy link to clipboard
Copied
Dear Kasyank,Marijan
Thanks for your help!
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
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,
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 )
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,
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 )
Copy link to clipboard
Copied
Ok, now I understand. Thank you very much for the explanation.
Regards,