Clipping Masks - Current Bane of my Life.
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):

What it should be doing (just vertical flip):

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)