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.
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
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
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.
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
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. 🙂
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
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
Copy link to clipboard
Copied
Thanks Manan, that makes sense. I appreciate your help.
- Mark