Jump to content

 
Photo

Releasing AI clipping masks with javascript

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Tamandua

Tamandua

    Newbie

  • Validated Member
  • Pip
  • 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.

Thank you!

#2
frax

frax

    Hall of Fame

  • Associate Admin
  • PipPipPipPipPipPipPip
  • 2,309 posts
  • Gender:Male
  • Location:Stockholm, Sweden
  • Interests:music, hiking, friends, nature, photography, traveling. and maps!
  • Sweden

Yes you can do it in Illustrator javascript.

Look in the Illustrator Javascript reference, and there is a clipped attribute to e.g. groupItems. Or if the structure of the documents is predictable you can just remove the first item in a group.
Hugo Ahlenius
Nordpil - custom maps and GIS
http://nordpil.com/
Twitter

#3
frax

frax

    Hall of Fame

  • Associate Admin
  • PipPipPipPipPipPipPip
  • 2,309 posts
  • Gender:Male
  • Location:Stockholm, Sweden
  • Interests:music, hiking, friends, nature, photography, traveling. and maps!
  • Sweden

Tamandua - I have done similar things in the past, PM if you are interested in a quote for a script to perform this on a folder of files.
Hugo Ahlenius
Nordpil - custom maps and GIS
http://nordpil.com/
Twitter

#4
Brian Moran

Brian Moran

    Contributor

  • Validated Member
  • PipPip
  • 32 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.

/* remove clipping paths from main layers */

for (var ii = newLayerCount - 1; ii >= 0; ii--) {

	var topLayer=myDoc.layers[ii];

	for(p=topLayer.groupItems.length - 1;p>=0; p--){

		 if(topLayer.groupItems[p].pathItems.clipping = true){

			 topLayer.groupItems[p].pathItems[0].remove()}

	 }

}



/* remove clipping paths from sub layers */

for (var ii = newLayerCount - 1; ii >= 0; ii--) {

	var topLayer=myDoc.layers[ii];		

		 if(topLayer.layers.length>0){

			 for(var iii = topLayer.layers.length - 1; iii >= 0; iii--){

				 var subLayer = topLayer.layers[iii];

				 subLayer.visible = true

				 subLayer.locked = false

				 for(s=subLayer.groupItems.length - 1;s>=0;s--){

					 if(subLayer.groupItems[s].pathItems.clipping = true){

						 subLayer.groupItems[s].pathItems[0].remove()}

				  }

			  }

		}		 

}


#5
Aracinth

Aracinth

    Newbie

  • New Member
  • Pip
  • 1 posts
  • No Country Selected

Hey,

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

 

Cheers!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

-->