Answered
Resize clipping mask to Artboard
I would like to know how to check if the selected object has a clipping mask, and resize the clipping mask to the active artboard. Please let me know if you have any additional info about that.
I would like to know how to check if the selected object has a clipping mask, and resize the clipping mask to the active artboard. Please let me know if you have any additional info about that.
Hi @StefanStehlik, I wrote a quick script that tries to do what you described. Please give it a try and let me know how it goes.
- Mark
/**
* Resize Clipping Mask To Active Artboard Rect.
*/
(function () {
var doc = app.activeDocument,
item = doc.selection[0];
resizeClippingMaskToActiveArtboard(item);
/**
* Resizes item's clipping mask
* to match artboard bounds.
* @author m1b
* @version 2022-10-20
* @param {GroupItem} item - an Illustrator GroupItem with clipping mask.
* @returns {Boolean} - success.
*/
function resizeClippingMaskToActiveArtboard(item) {
if (
item == undefined
|| !item.hasOwnProperty('clipped')
|| item.clipped !== true
)
// no clipping mask
return;
var mask;
for (var i = 0; i < item.pageItems.length; i++) {
if (item.pageItems[i].clipping == true) {
mask = item.pageItems[i];
break;
}
}
if (mask == undefined)
return false;
// get item's parent document
var doc = item;
while (
doc.hasOwnProperty('parent')
&& doc.constructor.name != 'Document'
)
doc = doc.parent;
var ab = doc.artboards[doc.artboards.getActiveArtboardIndex()],
bounds = ab.artboardRect;
// set mask size to match artboard rect
mask.position = [bounds[0], bounds[1]];
mask.width = bounds[2] - bounds[0];
mask.height = -(bounds[3] - bounds[1]);
};
})();
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.