Apply Multiply Effect and Clipping Path then Group images.
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Apply Multiply Effect and Clipping Path then Group images.
- This topic has 21 replies, 4 voices, and was last updated 5 years ago by David Blatner.
-
AuthorPosts
-
-
May 20, 2016 at 10:07 am #85065Masood AhmadParticipant
Hello Everyone,
I need a JavaScript that can do the following in one go in InDesign, can anyone help me please.
1. Copy the selected image to the clipboard;
2. Apply Multiply effect to the selected image;
3. Paste in Place the image from Clipboard;
4. Apply the Photoshop Clipping Path to the top image.
5. Group both the image.PS: The output will be a group of two images. The image at the bottom will have the Multiply effect. The image on the top will have the clipping path.
Thanks in advance.
-
May 20, 2016 at 10:13 am #85066Ari SingerMember
This can definitely be done. If I’ll have an extra moment I’ll try to do something for you.
G’luck! -
May 20, 2016 at 10:21 am #85067Masood AhmadParticipant
Thanks Ari. I hope the script will be available for me by Monday. Good Luck and thanks in advance for your time and favour.
-
May 20, 2016 at 10:22 am #85068Ari SingerMember
Will probably have it ready for today.
-
May 20, 2016 at 11:58 am #85073Ari SingerMember
Here you go!
I understood that the top image has to stay with the regular blending mode and not multiply, am I correct? Becuase this is how I wrote the script:
//Ari S. - [email protected] app.scriptPreferences.enableRedraw = false; app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ try{ var mySelection = app.selection[0]; var bottomObject = mySelection; var topObject = bottomObject.duplicate(); bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; try { topObject.pageItems.item(0).clippingPath.appliedPathName = topObject.pageItems.item(0).clippingPath.photoshopPathNames[0]; topObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; try { var myGroup = bottomObject.parent.groups.add ([bottomObject, topObject]); app.select(myGroup); } catch (myError) { alert("could not group successfully"); } } catch (myError) { alert("Selected image does not have a Photoshop path applied") } } catch (myError){ alert("Make sure you selected a graphic frame"); } }
G’luck!
-
May 21, 2016 at 10:43 pm #85080Ari SingerMember
I modified the script a bit, so it should work individually even when multiple graphics are selected.
//Ari S. - [email protected] app.scriptPreferences.enableRedraw = false; // 'Undo' will undo the entire script app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ // Capture the current selections in array var mySelections = app.selection; for (var i = 0; i < mySelections.length; i++) { try{ var bottomObject = mySelections[i]; var topObject = bottomObject.duplicate(); bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; try { topObject.pageItems.item(0).clippingPath.appliedPathName = topObject.pageItems.item(0).clippingPath.photoshopPathNames[0]; topObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; try { var myGroup = bottomObject.parent.groups.add ([bottomObject, topObject]); app.select(myGroup); } catch (myError) { // If it can't group alert("could not group successfully"); } } catch (myError) { // If it can't apply the Photoshop path then it obviously does not have one alert("Selected image does not have a Photoshop path applied") } } catch (myError){ // If it can't duplicate the object or apply multiply then it's obviously not a graphic frame alert("Make sure you selected a graphic frame"); } } }
-
May 23, 2016 at 2:59 am #85081Masood AhmadParticipant
Greetings of the hour Ari.
Both the scripts works perfectly fine. There wasn’t a single glitch in them. I don’t know how to thank you. Million thanks for sorting it out so quickly and efficiently.
-
May 23, 2016 at 6:55 am #85100Ari SingerMember
My pleasure, Masood.
I would advise you to use the second version of the script. It works just like the first, but it can also handle multiple selections at once.
BTW, for extra efficiency, assign a keyboard shortcut to the script.
Enjoy!
-
May 25, 2016 at 6:28 am #85201Masood AhmadParticipant
Thanks Ari for the suggestions. However, we have started using both the scripts as needed.
Today I receive one file where the images have the clipping path applied. Therefore, we have to manually remove the clipping path on the images and then run the script.
Is it possible that the script can apply “None” clipping path to the bottom image if a image may or may not contain the clipping path.
I tried, but failed. I am also looking for someone who can teach me JavaScript. Can you spread some light on this part too.
-
May 25, 2016 at 7:18 am #85203Ari SingerMember
Here you go. This is the updated script that removes the clipping path from the bottom object:
//Ari S. - [email protected] app.scriptPreferences.enableRedraw = false; // 'Undo' will undo the entire script app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ // Capture the current selections in array var mySelections = app.selection; for (var i = 0; i < mySelections.length; i++) { try{ var bottomObject = mySelections[i]; var topObject = bottomObject.duplicate(); bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; try { topObject.pageItems.item(0).clippingPath.appliedPathName = topObject.pageItems.item(0).clippingPath.photoshopPathNames[0]; topObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; bottomObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.NONE; try { var myGroup = bottomObject.parent.groups.add ([bottomObject, topObject]); app.select(myGroup); } catch (myError) { // If it can't group alert("could not group successfully"); } } catch (myError) { // If it can't apply the Photoshop path then it obviously does not have one alert("Selected image does not have a Photoshop path applied") } } catch (myError){ // If it can't duplicate the object or apply multiply then it's obviously not a graphic frame alert("Make sure you selected a graphic frame"); } } }
Only one line was added:
bottomObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.NONE;
-
May 25, 2016 at 7:31 am #85205Masood AhmadParticipant
Great help, thanks a ton. Works perfectly.
-
July 11, 2016 at 5:25 am #86408Masood AhmadParticipant
Hi Ari,
How will you modify the script that will allow a user to select a particular clipping path from the list.
-
July 11, 2016 at 7:03 pm #86446Ari SingerMember
If I understand correctly, you want to be able to select which Photoshop path to use from the original file, correct?
-
July 11, 2016 at 7:43 pm #86449Ari SingerMember
This should work:
//Ari S. - [email protected] app.scriptPreferences.enableRedraw = false; // 'Undo' will undo the entire script app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ // Capture the current selections in array var mySelections = app.selection; // Capture all the paths from the selected PSD try { var paths = mySelections[0].pageItems.item(0).clippingPath.photoshopPathNames; var myDialog = app.dialogs.add({name:"Select PSD Clipping Path", canCancel:true}); with (myDialog) { with(dialogColumns.add()) { with(dialogRows.add()) { staticTexts.add ({staticLabel:"Select the clipping path that you want:"}); with(dialogRows.add()) { var myPathDdl = dropdowns.add({minWidth:100}); myPathDdl.stringList = paths; myPathDdl.selectedIndex = 0; } } } } } catch(myError) { alert("Make sure it's a PSD"); exit(); } if (myDialog.show() == true) { for (var i = 0; i < mySelections.length; i++) { try{ var bottomObject = mySelections[i]; var topObject = bottomObject.duplicate(); bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; try { topObject.pageItems.item(0).clippingPath.appliedPathName = topObject.pageItems.item(0).clippingPath.photoshopPathNames[myPathDdl.selectedIndex]; topObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; bottomObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.NONE; try { var myGroup = bottomObject.parent.groups.add ([bottomObject, topObject]); app.select(myGroup); } catch (myError) { // If it can't group alert("could not group successfully"); } } catch (myError) { // If it can't apply the Photoshop path then it obviously does not have one alert("Selected image does not have a Photoshop path applied") } } catch (myError){ // If it can't duplicate the object or apply multiply then it's obviously not a graphic frame alert("Make sure you selected a graphic frame"); } } } myDialog.destroy(); }
-
July 14, 2016 at 6:13 pm #86534Ari SingerMember
Here’s the fixed script so that it pops up a dialog on each individual item when selected.
//Ari S. - [email protected] app.scriptPreferences.enableRedraw = false; // 'Undo' will undo the entire script app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ // Capture the current selections in array var mySelections = app.selection; for (var i = 0; i < mySelections.length; i++) { try { var bottomObject = mySelections[i]; app.select(bottomObject); var paths = bottomObject.pageItems.item(0).clippingPath.photoshopPathNames; var myDialog = app.dialogs.add({name:"Select PSD Clipping Path", canCancel:true}); with (myDialog) { with(dialogColumns.add()) { with(dialogRows.add()) { staticTexts.add ({staticLabel:"Select the clipping path that you want:"}); with(dialogRows.add()) { var myPathDdl = dropdowns.add({minWidth:100}); myPathDdl.stringList = paths; myPathDdl.selectedIndex = 0; } } } } if (myDialog.show() == true) { var topObject = bottomObject.duplicate(); bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; topObject.pageItems.item(0).clippingPath.appliedPathName = topObject.pageItems.item(0).clippingPath.photoshopPathNames[myPathDdl.selectedIndex]; topObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; bottomObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.NONE; var myGroup = bottomObject.parent.groups.add ([bottomObject, topObject]); app.select(myGroup); myDialog.destroy(); } } catch (myError) {} } }
-
July 15, 2016 at 3:22 am #86535Masood AhmadParticipant
Thanks Ari, It is working fine now. I just added one line to apply Normal Blending mode to the top image.
topObject.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
-
January 20, 2017 at 6:19 am #91442Masood AhmadParticipant
Hi Ari,
Based on your script I extracted some of the codes and created a new one to suit my new requirement.
//Ari S. - [email protected]
app.scriptPreferences.enableRedraw = false;
// 'Undo' will undo the entire script
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script");
function main(){
// Capture the current selections in array
var mySelections = app.selection;
for (var i = 0; i < mySelections.length; i++) {
try{
var myObject = mySelections[i];
try {
myObject.pageItems.item(0).clippingPath.appliedPathName = myObject.pageItems.item(0).clippingPath.photoshopPathNames[0];
myObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH;
}
catch (myError) {
// If it can't apply the Photoshop path then it obviously does not have one
alert("Selected image does not have a Photoshop path applied")
}
}
catch (myError){
// If it can't duplicate the object or apply multiply then it's obviously not a graphic frame
alert("Make sure you selected a graphic frame");
}
}
}
In the above code, I do not want the Duplicate Catch error as the script is not duplicating anything:
catch (myError){
// If it can't duplicate the object or apply multiply then it's obviously not a graphic frame
alert("Make sure you selected a graphic frame");
}
Can you get rid of it.
Secondly, I would like to add Fitting option for all the selected images(s) to “Fit Content to Frame”. Can you please help me do so.
However, you’ll laugh at my code when I tried:
myObject.pageItems.item(0).frameFit = FittingOptions.CONTENT_TO_FRAME;
Thanks in advance!
-
January 24, 2017 at 5:11 am #91528Masood AhmadParticipant
Can anyone suggest something on this…
-
January 24, 2017 at 10:40 am #91534Ari SingerMember
Hi, Masood. Sorry for the delay. This should work:
app.scriptPreferences.enableRedraw = false; // 'Undo' will undo the entire script app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script"); function main(){ // Capture the current selections in array var mySelections = app.selection; for (var i = 0; i < mySelections.length; i++) { var myObject = mySelections[i]; try { myObject.pageItems.item(0).clippingPath.appliedPathName = myObject.pageItems.item(0).clippingPath.photoshopPathNames[0]; myObject.pageItems.item(0).clippingPath.clippingType = ClippingPathType.PHOTOSHOP_PATH; } catch (myError) { // If it can't apply the Photoshop path then it obviously does not have one alert("Selected image does not have a Photoshop path applied") } myObject.fit(FitOptions.contentToFrame); } }
-
January 25, 2017 at 6:25 am #91573Masood AhmadParticipant
Thanks Ari,
No issues. You might be busy :) This wasn’t urgent.
The script worked well, however, the ‘contentToFrame’ was filling the image as stretched. Therefore, I tried to edit the script and finally added few lines, like these:
myObject.fit(FitOptions.CONTENT_TO_FRAME);
myObject.fit(FitOptions.PROPORTIONALLY);
myObject.fit(FitOptions.CENTER_CONTENT);
myObject.fit(FitOptions.FRAME_TO_CONTENT);
-
March 19, 2019 at 1:01 pm #115447Kirsten McMillanMember
Could you guys help me with a script that will turn on the Clipping Path on all images, on all pages, in a document?
-
March 19, 2019 at 1:11 pm #115448David BlatnerKeymaster
@Kirsten: Here’s one that will turn them all off: https://creativepro.com/topic/release-clipping-masks-on-all-selected-objects
Maybe that can be modified.
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.