Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rotating a clipping mask by javascript went wrong

Engaged ,
Aug 15, 2021 Aug 15, 2021

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

 

 

 

TOPICS
Bug , Scripting
934
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Aug 15, 2021 Aug 15, 2021

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

...
Translate
Adobe
Guide ,
Aug 15, 2021 Aug 15, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 15, 2021 Aug 15, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 15, 2021 Aug 15, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 15, 2021 Aug 15, 2021
LATEST

ok, thanks for the tip. I will try the second one 🙂

 

have a good sunday.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines