Copy link to clipboard
Copied
I have noticed that rotating a clipping mask by javascript gives a different (wrong) result than rotating it by hand.
I have an artboard 100 x 100 px and three rectangles.
(A) Rectangle 3, top left, is partially outside the artboard.
(B) The clipping mask is the same size as the artboard 100 x 100 px.
(C) I choose the centre as the pivot point.
(D) I rotate the clipping mask by +90°.
The result is correct. The clipped square is then at the bottom left.
(E) I undo the last step and call my Javascript, which takes the first object (Clipping Mask) to rotate it +90° around the centre.
The result is wrong. The clipping mask is no longer in the centre of the artboard.
If I haven't done anything wrong, then I have found a bug that is only visible through Javascript:
var vDocRef = activeDocument;
vDocRef.pageItems[0].rotate(90, true, false, false, false, Transformation.CENTER);
For a specific rotation, you can calculate where your centre should be and translate the difference. So in your case it would be something like
var vDocRef = activeDocument;
vDocRef.pageItems[0].rotate(90, true, false, false, false, Transformation.CENTER);
vDocRef.pageItems[0].translate(0, - vDocRef.pageItems[2].width / 2);
But this will work for this specific rotation only. If you rotate again, you'll go offset again.
Alternatively, you could make your group symmetrical by adding an invisible
...Copy link to clipboard
Copied
You haven't done anything wrong. When you rotate a clipping mask manually, you rotate around the centre of the "clipping path" (the path doing the masking).
Scripting wise, there is no clipping mask item in a true sense. A clipping mask is just a group with the "clipped" perperty set to true. So when you rotate it, you rotate around the centre of the group.
Copy link to clipboard
Copied
Thanks for the answer. But what can I do to get it right? I tried to move the rotated group, but the no godd result.
Copy link to clipboard
Copied
For a specific rotation, you can calculate where your centre should be and translate the difference. So in your case it would be something like
var vDocRef = activeDocument;
vDocRef.pageItems[0].rotate(90, true, false, false, false, Transformation.CENTER);
vDocRef.pageItems[0].translate(0, - vDocRef.pageItems[2].width / 2);
But this will work for this specific rotation only. If you rotate again, you'll go offset again.
Alternatively, you could make your group symmetrical by adding an invisible item. So you could add a hidden copy of the green rectangle to the right lower corner. This will work for any rotation.
Copy link to clipboard
Copied
ok, thanks for the tip. I will try the second one 🙂
have a good sunday.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more