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.

Viewing 20 reply threads
  • Author
    Posts
    • #85065
      Masood Ahmad
      Participant

      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.

    • #85066
      Ari Singer
      Member

      This can definitely be done. If I’ll have an extra moment I’ll try to do something for you.
      G’luck!

    • #85067
      Masood Ahmad
      Participant

      Thanks Ari. I hope the script will be available for me by Monday. Good Luck and thanks in advance for your time and favour.

    • #85068
      Ari Singer
      Member

      Will probably have it ready for today.

    • #85073
      Ari Singer
      Member

      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!

    • #85080
      Ari Singer
      Member

      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");
                  }
              }
          }
      
    • #85081
      Masood Ahmad
      Participant

      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.

    • #85100
      Ari Singer
      Member

      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!

    • #85201
      Masood Ahmad
      Participant

      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.

    • #85203
      Ari Singer
      Member

      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;

    • #85205
      Masood Ahmad
      Participant

      Great help, thanks a ton. Works perfectly.

    • #86408
      Masood Ahmad
      Participant

      Hi Ari,

      How will you modify the script that will allow a user to select a particular clipping path from the list.

    • #86446
      Ari Singer
      Member

      If I understand correctly, you want to be able to select which Photoshop path to use from the original file, correct?

    • #86449
      Ari Singer
      Member

      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();
          }
      
    • #86534
      Ari Singer
      Member

      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) {}
      			}
      		}
      
    • #86535
      Masood Ahmad
      Participant

      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;

    • #91442
      Masood Ahmad
      Participant

      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!

    • #91528
      Masood Ahmad
      Participant

      Can anyone suggest something on this…

    • #91534
      Ari Singer
      Member

      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);		
      		}
      	}
      
    • #91573
      Masood Ahmad
      Participant

      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);

    • #115447

      Could you guys help me with a script that will turn on the Clipping Path on all images, on all pages, in a document?

Viewing 20 reply threads
  • You must be logged in to reply to this topic.
>