Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hi everyone, is there a script for batch clipping masks? Thank you

Explorer ,
Jun 28, 2021 Jun 28, 2021

I often use scripts to cut masks in batches in my work. I hope someone can help me. Thank you.

TOPICS
Feature request , Scripting , Third party plugins
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jul 01, 2021 Jul 01, 2021

I think I overthought things. The following should make a clipping mask of each two overlapping selected items, whatever the masked artwork is (group, compound path, et cetera).  See if it works for you.

 

var selectedItems = app.activeDocument.selection;
var a = [];
var test = function(path1, path2) {
    var b1 = path1.geometricBounds;
    var b2 = path2.geometricBounds;
    return (b1[2] > b2[0] && b1[0] < b2[2]) && (b1[3] < b2[1] && b1[1] > b2[3]);
}
for (var i = 0; i < selectedItems.length ; 
...
Translate
Adobe
Community Expert ,
Jun 28, 2021 Jun 28, 2021

Just to help clarify, could you post screenshot of the expanded layers palette before and after the process? Expand the layer so we can see each page item—one before the action and once again afterwards. Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2021 Jun 29, 2021

Hello m1b, please see the demo GIF picture, thank you66.gif

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 29, 2021 Jun 29, 2021

Is the plan to target the items by selecting them?  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2021 Jun 29, 2021

Determine the goal by selecting the project Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 29, 2021 Jun 29, 2021

For the simplest case, where items are path items (i.e. not group items or compound path items), the following makes a clipping mask of each two overlapping selected items:

 

var selectedItems = app.activeDocument.selection;
var a = [];
var test = function(path1, path2) {
    var b1 = path1.geometricBounds;
    var b2 = path2.geometricBounds;
    return (b1[2] > b2[0] && b1[0] < b2[2]) && (b1[3] < b2[1] && b1[1] > b2[3]);
}
for (var i = 0; i < selectedItems.length ; i++) {
    for (var j = 0; j < selectedItems.length ; j++) {
        if (j != i && test(selectedItems[i], selectedItems[j])) {
            if (!selectedItems[i].done || !selectedItems[j].done) {
                var x = [];
                x.push(selectedItems[i]);
                x.push(selectedItems[j]);
                a.push(x);
                selectedItems[i].done = true;
                selectedItems[j].done = true;
                if (x[0].zOrderPosition < x[1].zOrderPosition) {
                    var temp = x[0];
                    x[0] = x[1];
                    x[1] = temp;
                }
            }
        }
    }
}
for (var i = 0; i < a.length; i ++) {
    var group = app.activeDocument.groupItems.add();
    a[i][0].moveToEnd(group);
    a[i][1].moveToEnd(group);
    group.clipped = true;
}

 

For a more comprehensive approach, you could try groupOverlappingObjects by John Wundes, adding the following right at the end of the script:

 

for (var i = 0; i < app.activeDocument.groupItems.length; i++) {
    app.activeDocument.groupItems[i].clipped = true;
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2021 Jun 30, 2021

Hello femke blanco, I don’t know how to write scripts. Will the code of group projects and compound path projects be complicated? Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 01, 2021 Jul 01, 2021

I think I overthought things. The following should make a clipping mask of each two overlapping selected items, whatever the masked artwork is (group, compound path, et cetera).  See if it works for you.

 

var selectedItems = app.activeDocument.selection;
var a = [];
var test = function(path1, path2) {
    var b1 = path1.geometricBounds;
    var b2 = path2.geometricBounds;
    return (b1[2] > b2[0] && b1[0] < b2[2]) && (b1[3] < b2[1] && b1[1] > b2[3]);
}
for (var i = 0; i < selectedItems.length ; i++) {
    if (!selectedItems[i].done) {
        for (var j = 0; j < selectedItems.length ; j++) {
            if (j != i && test(selectedItems[i], selectedItems[j])) {
                var x = [];
                x.push(selectedItems[i]);
                x.push(selectedItems[j]);
                a.push(x);
                selectedItems[j].done = true;
            }
        }
    }
}
for (var i = 0; i < a.length; i ++) {
    var group = app.activeDocument.groupItems.add();
    a[i][0].moveToEnd(group);
    a[i][1].moveToEnd(group);
    group.clipped = true;
}

 

 

Untitled1.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2021 Jul 01, 2021

Thank you femkeblanco, this is exactly what I want, very good

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2022 Jul 28, 2022

Your approach is what im looking for. Just got over this post been looking this for allmost 10 years work arround, but the script doesn't seem to work. Tried to click paths, images in a batch way but it isn't working. I have now 2022, hope this can be fixed or other wise explain how to use it. Litteraly is a must on Illustrator.

GEtting this error https://postimg.cc/NLQJf8kM

Thanks for the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 28, 2022 Jul 28, 2022

The script does not manage layers.  The error message implies a layer, presumably the first, is either locked or invisible.  Try changing the fifth line from the bottom from

var group = app.activeDocument.groupItems.add();

to

var group = a[i][0].parent.groupItems.add();

 To use, just select the items in question and run. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2022 Jul 28, 2022
LATEST

Works perfect... This script is gold man ❤️

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2021 Jul 01, 2021

It may be pretty useful if you were providing a couple of Illustrator sample files including some clear instructions that may explain what exactly you are going to do.

 

Also, which version of Illustrator are you using?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines