Skip to main content
Known Participant
November 10, 2008
Answered

Remove clipping mask

  • November 10, 2008
  • 12 replies
  • 93290 views
I need to remove the clipping mask in illustrator file through programmatically(Visual Basic (or) Javascript). Kindly advice me.

Thanks,
Prabudass
This topic has been closed for replies.
Correct answer KennethWebb

I realize this is an old thread, but I ran across it while looking for a solution to removing multiple clipping masks scattered throughout a document.

If you need to remove all the clipping masks from a document, here is a pretty simple script that will check all the pageItems and remove any that are being used as a clipping mask.

Comment out the last line if you don't want to see how many paths were deleted.  Its not a necesarry feature, but I like to know how many objects get deleted when I run something like this.

#target Illustrator

// script.name = RemoveClippingMasks.jsx

// script.description = deletes all PageItems being used as clipping masks.

// script.parent = Kenneth Webb // 01/07/2013

// script.elegant = true?

var docRef = app.activeDocument;

var clippingCount = 0

clipScan()

//loops through all pageItems, removing those that are clipping masks

function clipScan () {

    for (i=docRef.pageItems.length-1;i>=0;i--) {

        if (docRef.pageItems.clipping == true){

            docRef.pageItems.remove();

            clippingCount++;

        }

    }

};

alert ("All "+clippingCount+" Clipping Masks Removed")


Cheers!

12 replies

CarlosCanto
Community Expert
Community Expert
September 25, 2020

the forums migrated to a new platform and all scripts got ruined. 

 

here's an updated version

#target Illustrator

// script.name = RemoveClippingMasks.jsx

// script.description = deletes all pathItems being used as clipping masks that are visible and unlocked.

// script.parent = Kenneth Webb // 09/26/2013

var docRef = app.activeDocument;

var clippingCount = 0

clipScan(docRef) // searches the whole document

//clipScan(docRef.activeLayer); // searches the active layer

function clipScan (container) {

    for (i=container.pathItems.length-1;i>=0;i--) {

var item = container.pathItems[i];

        if (item.clipping == true && item.editable == true){ //screens for locked or hidden items

            container.pathItems[i].remove();

            clippingCount++;

        }

    }

};

alert (clippingCount+" Clipping Masks Removed")
Participating Frequently
December 21, 2021

You rock, Carlos. Very useful script, thank you for updating it here.

pixxxelschubser
Community Expert
Community Expert
July 9, 2020

@AG2011b143 wrote: "Yet another Adobe screw up. Every update brings new woes."

 

Keep cool.

You know, Illustrator is not a PDF editor. Like Monika said.
😉

 

----------------------------------------------------------------------


The script written in 2013 has stopped working.


Hmmm.
However, this is not a problem of the original script or an update to a newer program version of the Adobe software.

 

The main problem is:
The switch to the new forum software from Jive to Khoros has unfortunately damaged some of the older good scripts.

 

Usually a counter "[i]" is missing in the script. Like here too.

Try the following version. I have inserted the (presumably) missing counters. Hope this is ok for Kenneth Webb, the author.

#target Illustrator

// script.name = RemoveClippingMasks.jsx
// script.description = deletes all PageItems being used as clipping masks.
// script.parent = Kenneth Webb // 01/07/2013
// script.elegant = true?

var docRef = app.activeDocument;
var clippingCount = 0;

clipScan()

//loops through all pageItems, removing those that are clipping masks
function clipScan () {
    for (i=docRef.pageItems.length-1;i>=0;i--) { 
        if (docRef.pageItems[i].clipping == true) {
            docRef.pageItems[i].remove();
            clippingCount++;
        }
    }
};

alert ("All "+clippingCount+" Clipping Masks Removed");

 

If that works for you

have fun

😉

 

Inspiring
July 9, 2020

This got me all excieted but then it didn't work - is there an update that will work with newer AI versions?

 

As a side note, unnessary clipping paths drive me INSANE - they can take 10-15 minutes to search out and delete and I simply do not have the time to waste doing this several times every day, so I end up finding other ways to print the job.

 

Yet another Adobe screw up. Every update brings new woes.

Monika Gause
Community Expert
Community Expert
July 9, 2020

Unnecessary clipping masks almost always are caused by importing (opening) a PDF that doesn't have an embedded AI file.

servicecom1
Participant
May 3, 2018

Thanks for sharing !

Participant
January 19, 2018

This is so great.  I can't thank you enough.  I wish I had found this years ago.

October 14, 2016

can you please specify from where u want to remove clipping mask?

pathItem or

groupitem?

rodrigo6
Participant
April 1, 2016

As simple as this..

  

erinm15
Participant
January 15, 2016

Easier than using a script:

1. Go into layers and select any <path> within any <Clipping Group>

2. Go to Select > Same > Fill & Stroke

3. Press delete

Qwertyfly___
Legend
January 18, 2016

do that when you have 200+ files to go through and your going to get bored real quick.

a script is the best course of action.

if you want to add an extra layer of robustness. it's worth noting that once created the clipping path can be moved anywhere in the group and still work.

it will NOT always be the top path...

erinm15
Participant
January 18, 2016

Doesn't matter what layer the clipping path is so I'm not sure what you're getting at there.

If you have 200+ files, I suppose you'd be better with a script, however, I'm not sure how many of us would ever be in that situation. If so, I would suggest changing your workflow instead of using scripts to remedy a bad situation.

Ducvo
Participant
October 16, 2015

Thank so much, that good cript

KennethWebbCorrect answer
Inspiring
January 7, 2013

I realize this is an old thread, but I ran across it while looking for a solution to removing multiple clipping masks scattered throughout a document.

If you need to remove all the clipping masks from a document, here is a pretty simple script that will check all the pageItems and remove any that are being used as a clipping mask.

Comment out the last line if you don't want to see how many paths were deleted.  Its not a necesarry feature, but I like to know how many objects get deleted when I run something like this.

#target Illustrator

// script.name = RemoveClippingMasks.jsx

// script.description = deletes all PageItems being used as clipping masks.

// script.parent = Kenneth Webb // 01/07/2013

// script.elegant = true?

var docRef = app.activeDocument;

var clippingCount = 0

clipScan()

//loops through all pageItems, removing those that are clipping masks

function clipScan () {

    for (i=docRef.pageItems.length-1;i>=0;i--) {

        if (docRef.pageItems.clipping == true){

            docRef.pageItems.remove();

            clippingCount++;

        }

    }

};

alert ("All "+clippingCount+" Clipping Masks Removed")


Cheers!

Inspiring
May 23, 2013

The script works fine. Nice.

Is it possible to do this not in the whole document, but only on a specific layer?

I tryed to modify the script, but it doesn't work.

Here is my try

#target Illustrator

 

var docRef = app.activeDocument;

clipScan()

function clipScan () {

    for (i=doc.layers['Passer'].pageItems.length-1;i>=0;i--) {

        if (doc.layers['Passer'].pageItems.clipping == true){

            doc.layers['Passer'].pageItems.remove();

           

        }

    }

};

Inspiring
August 18, 2013

Would you not be better off just looping the groupItems collection…? Seems a bit wasteful to trawl everything when this only applies to groups and their top path item…


Mark, you're partly right. A clipping mask is generated normally as the first pathItem in a group. When I revised this a few months back I update the search parameter having realized clipping mask objects can only be created from pathItems. Unfortunately shortly after, my laptop was stolen and I rather forgot about updating this thread. I seem to recall that if a clipping mask is ungrouped manually the pathItem used to mask the group still hangs around without a stroke or fill but with the clipping property still true. So, you could definitely narrow the search to all pathItems in groups and still have this be effective, but I choose to play it safe in case there are any odd exceptions and search all pathItems. Below you'll find an updated script... I can't really test it at the moment because I'm working from a smart phone, but if memory serves, this is how to disregard locked items. I added a third "if" param to check for visibility, but to be honest I don't recall if this is the proper way to go about it. Can someone test it?

Also, I never did get around to adding layer specificity. Anyone goin to take a crack at it? :-)

#target Illustrator

// script.name = RemoveClippingMasks.jsx

// script.description = deletes all PathItems being used as clipping masks that are visible and unlocked.

// script.parent = Kenneth Webb // 07/19/2013

// script.elegant = more true

var docRef = app.activeDocument;

var clippingCount = 0

clipScan()

function clipScan () {

    for (i=docRef.pathItems.length-1;i>=0;i--) {

var item = docRef.pathItems;

        if (item.clipping == true && item.locked == false && item.visible == true.){

            docRef.pathItems.remove();

            clippingCount++;

        }

    }

};

alert ("All "+clippingCount+" Clipping Masks Removed")