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

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

Explorer ,
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

809

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

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

Votes

Translate

Translate
Adobe
Community Expert ,
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.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

Is the plan to target the items by selecting them?  

Votes

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

Copy link to clipboard

Copied

Determine the goal by selecting the project Thank you

Votes

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

 

Votes

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
Explorer ,
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

Votes

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
Guide ,
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

Votes

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

Copy link to clipboard

Copied

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

Votes

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

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.

Votes

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
Guide ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

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. 

Votes

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

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 Expert ,
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?

Votes

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