Skip to main content
itsBenMason
Inspiring
May 27, 2017
Answered

Clipping Masks - Current Bane of my Life.

  • May 27, 2017
  • 1 reply
  • 595 views

Hellos,

So recently learning to make scripts in javascript for illustrator to make life easy and so on.

Managed to make a plugin that does the step/repeat even rotate and move etc (amazing right). But everything comes to a holt when i have a clipping makes with contents bigger than the mask.

If i try to rotate, it will rotate around the mid point of everything rather than the clipping mask path item. If i rotate the clipping mask path item nothing else rotates. I would like to make some functions that act just like the illustrator transformation methods work as if you was doing them by hand.

Examples:

Mine (doing both horizontal and vertical flips):

23f68f410b894757c9f6e7bb096e0293.gif

What it should be doing (just vertical flip):

94af21e8df21fa543a6daec699210520.gif

Clipping Masks seem to cause a bunch of issues when moving, rotating, reflecting wish it could be simpler

If anyone can throw us some guidance or show us some examples that would be bril. Thank you!

EDIT:

I have an idea and going to work with it to see if i can find a solution, still post if you think you can help but im 90% sure this will work!

Will post my solution when i work it out.

Solution

getClippingPath = function(clippingMask) {

        for (i=0; i< clippingMask.pathItems.length; i++) { 

            var ipath = clippingMask.pathItems

            if (ipath.clipping) { 

                return this.cleanPath(ipath);

            }   

        }

}

matchClipBounds = function(object, bounds) {

        var clip = getClippingPath(object);

        var clipLeft = clip.left;

        var clipTop = clip.top;

        var objExtraLeft = clipLeft - object.left;

        var objExtraTop = object.top - clipTop; 

        var left = bounds[0] - objExtraLeft;  

        var top = bounds[1] + objExtraTop; 

        object.left = left; 

        object.top = top;

}

   

Duplicate the clipping path before u make any changes.

Whatever u do to the selection - do to the duplicated item aswel.

E.G:

var clip = getClippingPath(object).duplicate(activeDocument, ElementPlacement.PLACEATEND);

object.rotate(45);

clip.rotate(45);

THEN after you have finished doing anything u need to do:

Align the selection to the duplicated clipping object:

matchClipBounds(object, clip.visibleBounds)

This topic has been closed for replies.
Correct answer itsBenMason

Solution

getClippingPath = function(clippingMask) {

        for (i=0; i< clippingMask.pathItems.length; i++) { 

            var ipath = clippingMask.pathItems

            if (ipath.clipping) { 

                return this.cleanPath(ipath);

            }   

        }

}

matchClipBounds = function(object, bounds) {

        var clip = getClippingPath(object);

        var clipLeft = clip.left;

        var clipTop = clip.top;

        var objExtraLeft = clipLeft - object.left;

        var objExtraTop = object.top - clipTop; 

        var left = bounds[0] - objExtraLeft;  

        var top = bounds[1] + objExtraTop; 

        object.left = left; 

        object.top = top;

}

   

Duplicate the clipping path before u make any changes.

Whatever u do to the selection - do to the duplicated item aswel.

E.G:

var object = activeDocument.selection[0];

var clip = getClippingPath(object).duplicate(activeDocument, ElementPlacement.PLACEATEND);

object.rotate(45);

clip.rotate(45);

THEN after you have finished doing anything u need to do:

Align the selection to the duplicated clipping object and remove the clip as we dont need it anymore:

matchClipBounds(object, clip.visibleBounds)

clip.remove();

1 reply

itsBenMason
itsBenMasonAuthorCorrect answer
Inspiring
May 27, 2017

Solution

getClippingPath = function(clippingMask) {

        for (i=0; i< clippingMask.pathItems.length; i++) { 

            var ipath = clippingMask.pathItems

            if (ipath.clipping) { 

                return this.cleanPath(ipath);

            }   

        }

}

matchClipBounds = function(object, bounds) {

        var clip = getClippingPath(object);

        var clipLeft = clip.left;

        var clipTop = clip.top;

        var objExtraLeft = clipLeft - object.left;

        var objExtraTop = object.top - clipTop; 

        var left = bounds[0] - objExtraLeft;  

        var top = bounds[1] + objExtraTop; 

        object.left = left; 

        object.top = top;

}

   

Duplicate the clipping path before u make any changes.

Whatever u do to the selection - do to the duplicated item aswel.

E.G:

var object = activeDocument.selection[0];

var clip = getClippingPath(object).duplicate(activeDocument, ElementPlacement.PLACEATEND);

object.rotate(45);

clip.rotate(45);

THEN after you have finished doing anything u need to do:

Align the selection to the duplicated clipping object and remove the clip as we dont need it anymore:

matchClipBounds(object, clip.visibleBounds)

clip.remove();