Hi @m1b
As per our discussion, see attached the before and after .ai file.
what i basically want is for the script to do, is to be able to clip mask anything be it grouped objects, clip masks or raster images. would you be able to adjust it to a all in one script or does it have to be three different ones.
a million tx for this.
Hi @peter__4654 here is a version that puts any kind of page item into a new clipping mask, using the selected paths. It seems to work okay on your sample document(s).
- Mark
/**
* @file Multi Clip Items.js
*
* Usage:
* 1. Select a bunch of overlapping path items with the
* "focus item" at the bottom (can be any type of item).
* 2. Run script.
*
* For each selected path item, will create a clipping group
* and insert the selected path item(s) as the new mask and
* the "focus item" as the clipped contents.
*
* @author m1b
* @version 2025-05-16
* @discussion https://community.adobe.com/t5/illustrator-discussions/java-script-help/m-p/15297349
*/
(function () {
var doc = app.activeDocument,
items = doc.selection;
if (
!items
|| items.length < 2
)
return alert("Please select path items with the 'contents' page item at the bottom.");
// this is going to be the contents of the new clipping group
var focusItem = selection.pop();
for (var i = items.length - 1; i >= 0; i--) {
var mask = items[i];
if ('PathItem' != mask.constructor.name)
// we only want path items (to use for clipping masks)
continue;
// duplicate the focus item
var contentsItem = focusItem.duplicate(mask, ElementPlacement.PLACEAFTER),
newClippingGroup = mask.layer.groupItems.add();
// move the path item into the clipping group
mask.move(newClippingGroup, ElementPlacement.PLACEATBEGINNING);
contentsItem.move(newClippingGroup, ElementPlacement.PLACEATEND)
// set up the new clipping mask
newClippingGroup.clipped = true;
mask.clipping = true;
}
// remove the original focus item
focusItem.remove();
})();