Skip to main content
StefanStehlik
Inspiring
October 20, 2022
Answered

Resize clipping mask to Artboard

  • October 20, 2022
  • 3 replies
  • 1656 views

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.

This topic has been closed for replies.
Correct answer m1b

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]);

    };

})();

 

3 replies

femkeblanco
Legend
October 20, 2022

I'm unsure if the OP wants to resize just the clipping path, a la @m1b 's script, or resize the visible artwork too. 

m1b
Community Expert
Community Expert
October 20, 2022

Yep, I'm unsure too. @StefanStehlik, feel free to post more specific details if you need to.

- Mark

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
October 20, 2022

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]);

    };

})();

 

StefanStehlik
Inspiring
October 21, 2022

Thank you, this is what I'm looking for

Mylenium
Legend
October 20, 2022

Clipping masks appear on the opacity and appearance panel, but in order to resize them independently you will need to release them so they behave like regular objects. Probably something that would be a good candidate for creating a little script so it can be done with a button click...

 

Mylenium

Monika Gause
Community Expert
Community Expert
October 20, 2022
quote

Clipping masks appear on the opacity and appearance panel,


By @Mylenium

 

They appear in the Layers panel.

Mylenium
Legend
October 21, 2022

Yeah, sorry, my bad. Was probably thinking about some other stuff.

 

Mylenium