Skip to main content
Participant
April 20, 2023
Question

JavaScript for rotating 'Direct Selection'

Oi!

 

I have a simple little script for rotating selected object.
It does the same if selected with 'Selection Tool' or 'Direct Selection Tool'.
In both cases the text in the object is rotating with the object.

var mySelection = app.selection;
if (mySelection.length > 0) {
var myAngle = -90;
var myCenter = [mySelection[0].geometricBounds[1], mySelection[0].geometricBounds[0]];
var myTransform = app.transformationMatrices.add({counterclockwiseRotationAngle: myAngle, anchorPoint: myCenter});
mySelection[0].transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.CENTER_ANCHOR, myTransform);
}

If I manually rotate with 'Rotate 90° CW' (see the attached video):
'Selection Tool' rotates also the text.
'Direct Selection Tool' does not rotate the text.

Any ideas how to put it in a script?

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Peter Kahrel
Community Expert
Community Expert
April 21, 2023

You need to get a reference to the object inside the rectangle. How was that page item put together?

Translate
asirgAuthor
Participant
April 21, 2023

Attached .indd (Adobe InDesign CC 2017.1 Release).
It explains how I created the object.

Thank you for your comments!

Translate
Robert at ID-Tasker
Legend
April 20, 2023

With Direct Selection Tool you are moving points of the Object - not the Object itself. 

I'm away from my computer so can't check - but I think you would have to move each PathPoint of the Path separately.

 

Translate
asirgAuthor
Participant
April 21, 2023

I guess, I should do the rotation for each PathPoint of the Path separately by 90 degrees CW with respect to the centroid of the object, but my knowledge of scripting is at a very basic level.
Thank you for your comments!

Translate