Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
InDesign - Javascript - Copy Object, Paste in Place, Group New Object with Original Selection

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:

  1. Copies selected image (for use in step #3).
  2. Applies "multiply" effect to the selected image.
  3. Pastes-in-place the original image (with no multiply effect).
  4. Looks for a specific photoshop path name (either 'X', 'FCP', or 'x').
  5. Applies first path it finds and alerts which was selected or alerts "no valid path exists" if none are available.
  6. 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.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

  1. It searches for a clipping path to match a specific string.
  2. User is alerted to which path has been applied or if no match is found.
  3. Image is copied (for step 6).
  4. Path is removed.
  5. Multiply blending mode is applied.
  6. Image copied in step 3 is pasted in place (with clipping path).
  7. Pasted image selection is added to current selection (image with multiply blending mode).
  8. Selection is grouped.
about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!