How to select and delete every clipping masks in an Illustrator document using javascript?

浪子不回头ぞ 提交于 2019-12-11 12:36:08

问题


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.


回答1:


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"); 


来源:https://stackoverflow.com/questions/35057879/how-to-select-and-delete-every-clipping-masks-in-an-illustrator-document-using-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!