Highlighted

onSave Event Listener to prompt scaled images

Community Beginner ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

Topics

Scripting

Views

61

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

onSave Event Listener to prompt scaled images

Community Beginner ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

Topics

Scripting

Views

62

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
Sep 03, 2020 0
Adobe Community Professional ,
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

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
Reply
Loading...
Sep 03, 2020 0
Community Beginner ,
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.

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
Reply
Loading...
Sep 03, 2020 0
Community Beginner ,
Sep 03, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Sep 03, 2020 0