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

onSave Event Listener to prompt scaled images

Explorer ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

Hi,

I recently got some InDesign files from various sources with text and images. In these files, images are scaled from 12% to 600%. So, my task is to fix the layout and send it back to the sender and they will resend it to me after editing. Chances are that they will again scale some of the images to their choice.

I tried the Jongware script, "ImageScaleInfo.jsx", but that is only giving me the scale information.

What I want is a type of Warning alert using the OnSave Event Listener that "Image(s) used in the document is scaled below 80% and above 120%.

Basically, I need a checkpoint that can alert me if the image is scaled below 80% or above 120%.

Can anyone help me with this.

Thanks,

Masood

TOPICS
Scripting

Views

322

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

Community Expert , Sep 03, 2020 Sep 03, 2020

Something like the following should work

#targetengine "save"
app.addEventListener("beforeSave", function(){
	for(var i = 0; i < app.documents[0].allGraphics.length; i++)
	{
		var img = app.documents[0].allGraphics[i]
		if((img.absoluteHorizontalScale < 80 || img.absoluteHorizontalScale > 120) || (img.absoluteVerticalScale < 80 || img.absoluteVerticalScale > 120))
		{
			alert("Image(s) used in the document is scaled below 80% and above 120%.")
			break;
		}
	}
})

-Manan

Votes

Translate

Translate
Community Expert ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

Something like the following should work

#targetengine "save"
app.addEventListener("beforeSave", function(){
	for(var i = 0; i < app.documents[0].allGraphics.length; i++)
	{
		var img = app.documents[0].allGraphics[i]
		if((img.absoluteHorizontalScale < 80 || img.absoluteHorizontalScale > 120) || (img.absoluteVerticalScale < 80 || img.absoluteVerticalScale > 120))
		{
			alert("Image(s) used in the document is scaled below 80% and above 120%.")
			break;
		}
	}
})

-Manan

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
Explorer ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

Hi Manan, It worked perfectly. Thanks again for your quick help.

 

PS: I sent you a message. Please check that and let me know.

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
Explorer ,
Sep 03, 2020 Sep 03, 2020

Copy link to clipboard

Copied

LATEST

Hi Manan,

I added some codes to the script to stop saving the file if the condition is true:

#targetengine "save"
app.addEventListener("beforeSave", function(scaledImages){
	for(var i = 0; i < app.documents[0].allGraphics.length; i++)
	{
		var img = app.documents[0].allGraphics[i]
		if((img.absoluteHorizontalScale < 80 || img.absoluteHorizontalScale > 120) || (img.absoluteVerticalScale < 80 || img.absoluteVerticalScale > 120))
		{
			alert("Image(s) used in the document is scaled below 80% and above 120%.")
			scaledImages.stopPropagation();
			scaledImages.preventDefault();  
			break;
		}
	}
})

 PS: Can you email me at: masood.designs@gmail.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