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

How to get image's path in before place event

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

348

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

Votes

Translate

Translate
Community Expert ,
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

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

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

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

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

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

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

Copy link to clipboard

Copied

LATEST

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

- Mark

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