Home > InDesign Scripts > Extract Clipping Path

Extract Clipping Path

If we want to extract clipping path from InDesign GUI we simply go to Object -> Clipping Path -> Covert Clipping Path to Frame, but how to do it through scripting? Another thing is that we can’t convert multiple selected images with clipping path to frames through GUI, but you can do it through script. I will cover just converting one selected frame, but we can loop through selection and do same to every image.

This was also published on Adobe’s InDesign scripting forum by me. This script is going to work just with single selected frame with clipping path applied to it.

First, we have to check if our selection contains image and clipping path applied. Next, (this is just beauty pass :D), if clipping path is Photoshop path or Alpha channel from image, we display path name. Then, we duplicate selection, extract clipping path, delete image, fill it with color and select it.

if(app.selection.length == 1){
    mySel = app.selection[0];
    try{myClipping = mySel.graphics[0].clippingPath;
        if(myClipping.clippingType == ClippingPathType.ALPHA_CHANNEL ||
            myClipping.clippingType == ClippingPathType.PHOTOSHOP_PATH){
                alert("Clipping path name: " + mySel.graphics[0].clippingPath.appliedPathName);
        }
        myFrame = mySel.duplicate(undefined,[0,0]);
        myFrame.graphics[0].clippingPath.convertToFrame();
        myFrame.graphics[0].remove();
        myFrame.fillColor = app.activeDocument.swatches.item("Registration");
        myFrame.select();
    }
    catch(e){alert("There is no clipping path applied!");}
}

If we want to achieve same effect like from InDesign GUI we use shorter script:

if(app.selection.length == 1){
    mySel = app.selection[0];
    try{myClipping = mySel.graphics[0].clippingPath;
        mySel.graphics[0].clippingPath.convertToFrame();
    }
    catch(e){alert("There is no clipping path applied!");}
}

Also, we can loop through available clipping paths, change them and stuff. Maybe I will cover that in future posts.

Have fun!😀

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: