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

Community Beginner ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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

Views

198

Likes

Translate

Translate

Report

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

Enthusiast , 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 ; ...

Likes

Translate

Translate
Enthusiast ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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 ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Enthusiast ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Is the plan to target the items by selecting them?  

Likes

Translate

Translate

Report

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 ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Determine the goal by selecting the project Thank you

Likes

Translate

Translate

Report

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
Enthusiast ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

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;
}

 

Likes

Translate

Translate

Report

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Enthusiast ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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