How to get image's path in before place event

New Here ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Hi,

I am creating a small utility which checks for special characters in image names when a image is placed inside any rectangle. If there is any special character then it throws up an dialog asking user rename the image.

I am not sure how to get the image name or path in the before place event. Events target is rectangle and the image has yet not been placed so i don't have access to image link there in the rectangle.

TOPICS
How to , Scripting

Views

144

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 1 Correct answer

Adobe Community Professional , Mar 06, 2022 Mar 06, 2022
The following should work #targetengine "test" app.documents[0].addEventListener('beforeImport', function(e){ alert(e.fullName) //Check you condition and if it fails, cancel the event e.preventDefault() }) -Manan

Likes

Translate

Translate
Adobe Community Professional ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

The following should work

#targetengine "test"
app.documents[0].addEventListener('beforeImport', function(e){
	alert(e.fullName)
	//Check you condition and if it fails, cancel the event
	e.preventDefault()
})

-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
community guidelines
New Here ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Hi Manan, i have already done this. my question here is inside which object or property of the event object can i access the images path or name or links path.

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
Adobe Community Professional ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Didn't you notice the alert, the alert is giving the full path of the image that you are trying to place. If the path does not meet your criteria just cancel the event.

-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
community guidelines
New Here ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Thanks Manan, I was looking into beforePlace event. Didn't realize that you used beforeImport event. thats why i was having trouble. Thanks for the help. 🙂

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
Adobe Community Professional ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

Hi @Manan Joshi, thanks for posting that. So am I right to think that an event listener is attached to a target engine? I noticed your script fails if I don't specify the target engine.

- Mark

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
Adobe Community Professional ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

Hi Mark,

So eventhandlers are something that we need to be functional even after the script finishes its execution, that is why we need to define it in a persistent engine. If we don't do that, the eventhandler ceases to exist after the script ends and we get an error, something like the object no longer exists.

Hope this makes sense

-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
community guidelines
Adobe Community Professional ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

LATEST

Thanks Manan, that makes sense. I appreciate your help.

- Mark

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