EDITED FOR CLARITY
I’ve created a script for InDesign to improve my workflow.
I select an image, then run the script, which performs as follows:
- Copies selected image (for use in step #3).
- Applies "multiply" effect to the selected image.
- Pastes-in-place the original image (with no multiply effect).
- Looks for a specific photoshop path name (either ‘X’, ‘FCP’, or ‘x’).
- Applies first path it finds and alerts which was selected or alerts "no valid path exists" if none are available.
- Script Ends with the pasted image selected.
Everything functions as intended; however, I would like to select BOTH images (the image with a clipping path and the image with the multiply effect) and group them. I’m getting caught up on how to select both images.
Here’s the original code (I intend to make Yuri’s edits to the copy and paste commands):
app.menuActions.item("$ID/Copy").invoke();
var myProperties = {
blendMode : BlendMode.MULTIPLY,
opacity : 100
};
for (i=0; i<app.selection.length; i++)
{
try {
app.selection[i].images[0].transparencySettings.blendingSettings.properties = myProperties;
}catch(e){}
}
app.menuActions.item("$ID/Paste in Place").invoke();
for (j=0; j<app.selection.length; j++)
{
try {
var myPathName = app.selection[0].images[0].clippingPath.photoshopPathNames;
var myPath = app.selection[0].images[0].clippingPath;
function working() {
for (var i = 0; i < myPathName.length; i++) {
if (myPathName[i] === "X") {
myPath.appliedPathName = myPathName[i];
alert ("X path activated");
return i;
} else if (myPathName[i] === "FCP") {
myPath.appliedPathName = myPathName[i];
alert ("FCP path activated");
return i;
} else if (myPathName[i] === "x") {
myPath.appliedPathName = myPathName[i];
alert ("x path activated");
return i;
}
}
alert ("No valid path exists");
}
working();
} catch (e) {}
}
Apologies if it’s not the cleanest code. I started learning javascript in my free time and this is one of the first scripts I wrote.
2
Answers
With Yuri's guidance I was able to solve my issue. I had to reorder the process slightly to account for how I was adding to the selection (maybe I didn't but it made sense to me and IT WORKS!). Here is the final code for anyone interested.
What happens and how does it work? User selects an image and runs the script
Still not sure if I understand the problem right. If you need to add some item to current selection it can be done this way:
edited to change
app.selected
toapp.selection
becauseselected
returned an error