2

I'm making extend scripts for Adobe Illustrator CS6 (javascript) and I need to delete every clipping masks of a document.

I already have a solution but it's not fast enough in big documents.

Here is my code:

var releaseClippingMasks = function(document)  {
  var pathItems = document.pathItems;
  log('Looking for clipping masks among ' + pathItems.length + ' elements');
  var n = 0;
  for(var p = pathItems.length - 1; p >= 0; p--) {
    if(p / 1000 == Math.round(p / 1000)) {
        log(p + ' remaining');
    }

    if(pathItems[p].clipping) { // accessing to the element [p] of pathItems takes a lot of time
        pathItems[p].remove();
        n++;
    }
  }
  log(n + ' deleted masks');
}

There are not so many clipping masks in my documents, but a lot of pathItems (100000+), so iterating takes a very long time.

Does anyone know a better way to select every clipping masks in a document by javascript? Any help would be very appreciated.

superrache
  • 650
  • 11
  • 26
  • 1
    Does `everyItem().getElements()` work in your Illustrator environment? For InDesign this is frequently used to 'detach' a live collection into a separate array, so accessing individual items can be much faster. And you already pointed that out as a likely candidate. – Jongware Jan 30 '16 at 20:41
  • There is no such a function in Illustrator environment. I just tried with InDesign and I didn't find it either. Anyway, if we manage to get every elements in an array, an iteration on each element should be done to find those who have a clipping mask. – superrache Apr 01 '16 at 08:05

1 Answers1

5

The fastest way to select all clipping mask and delete it:

// Select->Objects->Clipping Mask
app.executeMenuCommand("Clipping Masks menu item"); 
// Edit->Clear
app.executeMenuCommand("clear"); 
emax
  • 511
  • 1
  • 4
  • 13