Releasing AI clipping masks with javascript

Tamandua

Posted 14 May 2012 - 04:15 PM

Tamandua

Newbie

Validated Member

1 posts

United States

Hello,

I am exporting a large number of maps from AutoCAD to Illustrator and I need a way to release all the clipping masks that get exported. Is there a way to do this with javascript? I haven't been able to find any command for editing clipping masks in javascript.

Brian Moran

Posted 22 May 2012 - 03:42 PM

Brian Moran

Contributor

Validated Member

33 posts

Gender:Male

Location:Bay Area, California

United States

It is possible but you have to account for the fact that when you export to AI from ArcMap, it tends to put clipping paths with no stroke/fill in EACH layer, and often each layer is also grouped. So the trick to removing them with a script is to loop through each layer, and drill down through all groups to find paths where path.clipping=true, and then remove them. You can set path.clipping=false, but then the path is still there and clutters up your file, so I tend to use path[0].remove(). Here is a snippet from a script that does this-- your variable names will be different but you get the idea.

Aracinth

Posted 07 January 2013 - 05:13 PM

I ran across this thread awhile ago and was also having problems with clipping masks.

I got your script running Brian, but it wasn't quite what I needed.

Revisiting this problem after doing a lot of reading through the Adobe javascript manuals, I believe I've found a simpler solution.

The script still cycles through items looking for clipping masks to remove, but I realized I could loop through all the page items without having to "drill down" through layers, sublayers and groups looking for path item clipping masks.

Here is the script (it also includes a "clipping mask counter" that can be commented out... I just like to know how many items get deleted when I run something like this):

#target Illustrator

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].type = [PathItem]){

if (docRef.pageItems[i].clipping == true){

docRef.pageItems[i].remove();

clippingCount++;

}

}

}

};

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

If you find an issue with this you're welcome to drop me a line over on the Adobe forums... I actually just joined this forum because I thought I'd save anyone else trying to figure this out a bit of work! I appreciated your code and figured I could do the same. :-D