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

find image and then delete...

Community Beginner ,
Aug 26, 2009 Aug 26, 2009

Copy link to clipboard

Copied

Hi everyone,

I want to search particular images in the document with it's name and i want to delete those images from the document. How it can be done through script. Your help will be much appreciated.

Regards

Thiyagu

TOPICS
Scripting

Views

1.2K

Likes

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 2 Correct answers

Contributor , Aug 26, 2009 Aug 26, 2009

var del_list = ["foo.psd", "var.jpg", "hoge.tif"];

var my_doc = app.activeDocument;

var my_image = my_doc.allGraphics;

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

     var tmp_name = my_image.itemLink.name;

     for (var ii = 0; ii < del_list.length; ii++) {

          if (del_list[ii] === tmp_name) {

              my_image.parent.locked = false;

              my_image.remove();

          }

     }

}

--
seuzo
http://www.seuzo.jp/

Likes

Translate

Translate
Community Expert , Sep 28, 2022 Sep 28, 2022

If you're after a certain image, e.g. sunflower.png, use this:

app.documents[0].links.item('sunflower.png').parent.parent.remove();

If you want to remove that from 500 documents, use the above one-liner in this script:

https://creativepro.com/files/kahrel/indesign/batch_convert.html

Details on how to organise that are in the web page.

Peter

 

Likes

Translate

Translate
Contributor ,
Aug 26, 2009 Aug 26, 2009

Copy link to clipboard

Copied

var del_list = ["foo.psd", "var.jpg", "hoge.tif"];

var my_doc = app.activeDocument;

var my_image = my_doc.allGraphics;

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

     var tmp_name = my_image.itemLink.name;

     for (var ii = 0; ii < del_list.length; ii++) {

          if (del_list[ii] === tmp_name) {

              my_image.parent.locked = false;

              my_image.remove();

          }

     }

}

--
seuzo
http://www.seuzo.jp/

Likes

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 ,
Aug 26, 2009 Aug 26, 2009

Copy link to clipboard

Copied

Wow!!! Its working greatly. Thanks for your timely support.

Thanks and regards

Thiyagu

Likes

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
New Here ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

Morning - I found this while looking for a way to delete one image from over 500 docs - but not being a Java Expert in any way, I have an issue - with "Error 21 : Undefined is not an object:" in this line - "var tmp_name = my_image.itemLink.name;" - what am I missing? - BTW InDesign CC 2022 17.2.1

 

Thanks

Screenshot 2022-09-28 at 09.36.15.jpg

 

Likes

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 ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

If you're after a certain image, e.g. sunflower.png, use this:

app.documents[0].links.item('sunflower.png').parent.parent.remove();

If you want to remove that from 500 documents, use the above one-liner in this script:

https://creativepro.com/files/kahrel/indesign/batch_convert.html

Details on how to organise that are in the web page.

Peter

 

Likes

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
New Here ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

Awesome, thank you! I use Batch process all the time - never occurred to me. Maybe that's why I manage a Studio not an IT dept 🙂 (probably best)

 

Likes

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

LATEST

Hi @Clive5E0C ,

when this thread was moved to the new Adobe InDesign forum at the end of 2019 the code from 2009 was damaged!

Below the repaired version that I did not test:

 

var del_list = ["foo.psd", "var.jpg", "hoge.tif"];

var my_doc = app.activeDocument;
var my_image = my_doc.allGraphics;

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

	var tmp_name = my_image[i].itemLink.name;

	for (var ii = 0; ii < del_list.length; ii++)
	{

		if (del_list[ii] === tmp_name)
		{
			 my_image[i].parent.locked = false;
			 my_image[i].remove();
		}

	}
}

 

Let's discuss this a bit, code from 2009, written perhaps with InDesign CS4 or CS5 in mind:

There is a loop through the allGraphics array of the document.

With a current version of InDesign this means that also graphics could be stored in that array that have no itemLink at all and would error out the script. Pixels that are copy/pasted from e.g. PhotoShop inside an InDesign layout.

 

So best stay with Peter Kahrel's approach with a placed and linked image or graphic that can be addressed directly with the name property of the item's link:

https://www.indesignjs.de/extendscriptAPI/indesign16/#Link.html

 

The parent of that link will return the graphic itself. See the allGraphics array of a document.

The parent of that parent is the frame that contains the graphic.

Removing that frame will remove the graphic from the document.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Likes

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