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:
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.
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.
//look for clipping path 'X', 'FCP', or 'x' and apply it
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) {}
}
//copy image with clipping path
app.copy();
//remove clipping path
app.selection[0].images[0].clippingPath.clippingType = ClippingPathType.NONE;
//apply Multiply blend mode
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){}
}
//paste in place and add to current selection
var clippedImage = app.selection[0];
app.pasteInPlace();
clippedImage.select(SelectionOptions.ADD_TO)
//group selected images
app.menuActions.itemByName("$ID/Group").invoke();
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:
var item1 = app.selection[0]; // some selected item
app.paste(); // paste item which is selected now
item1.select(SelectionOptions.ADD_TO) // add the item1 to current selection
app.menuActions.itemByName("$ID/Group").invoke(); // group selected items
edited to change app.selected to app.selection because selected returned an error