Copy link to clipboard
Copied
Using the Selection Tool and Direct Selection Tool
How do I obtain the path of an image pasted inside?
I tried using .parent, but it didn't work.
var image = app.selection[0].parent;
var imagePath = image.itemLink.filePath;
The test file is here:
https://musetransfer.com/s/hlryv6cor
try {
//alert(app.selection[0].constructor.name);
if (app.selection[0].constructor.name == "Image") {
//alert("here");
var image = app.selection[0].parent;
var imagePath = image.itemLink.filePath;
//alert(imagePath);
}
else {
var image = app.selection[0].images[0];
var imagePath = image.itemLink.filePath;
//alert(imagePath);
}
} catch (e) { return }
Right, your if else statement trys to get the image inside of the Rectangle when it is selected.
Also, looks like there is some kind of corruption with your bottom 2 images—images[0] throws an error when the bottom image/frame is selected. Try allGraphics[0] — it works
try {
if (app.selection[0].constructor.name == "Image") {
var image = app.activeDocument.selection[0];
var imagePath = image.itemLink.filePath;
}
else {
var image = app.activeDocument.selec
Hi @dublove you seem to be struggling with this idea of "select tool" vs "direct selection tool". This is a false idea because with the selection tool we can select the frame OR the graphic (by clicking on the circle widget in the frame center). Instead, try to have a better understanding of what you have selected.
For scripting, this is my approach: I make a function that does all the heavy lifting. I use it and never have to think twice about it (until I find a bug!).
Here is an example, t
...Copy link to clipboard
Copied
Check the validity of the selection—your script fails when the selected image and its frame is nested inside of another frame.
var selectedFrame = app.selection[0];
alert(selectedFrame.images[0].isValid)
I get this from your sample file when the selection contains nested frames—image[0] is not valid
Copy link to clipboard
Copied
I definitely know the reason.
I am asking how to solve this problem.
Because the “paste inside” function is also commonly used.
Copy link to clipboard
Copied
Because the “paste inside” function is also commonly used.
You can paste image frames into other image frames multiple levels deep—I would never do it because it ads unnecessary complexity to the page.
This selected image is buried 4 frames deep. If the top parent frame is the selection it gets harder to drill down via scripting and check for an image.
Copy link to clipboard
Copied
Can only one image be opened by Photoshop at the same time?
This seems to be a dialog box popping up in PS.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now