Rotate single selected object

First, let’s clear how InDesign is working with selections. Selections are always in Arrays. So, first object in Array has index 0, second object is 1, and so on. For now, we are going to take a look just how to rotate a single object.

Method #1: (easier one)

Here is script for rotating just one selected object:

var myObj = app.selection[0];
myObj.rotationAngle = 45;

First, we put object in variable, and then apply rotationAngle to the object. Rotation angle is constant, so if you apply rotation once more with same settings, nothing will change. You can also check if object is rotated like this:

var myObj = app.selection[0];
alert(myObj.rotationAngle);

Ok, we have rotated object. It has been rotated around currently selected anchor point. If you want to change anchor point from script use this:

In this method we are creating transformation matrices, and we are going to add just one transformation matrix and that is rotation. After that, we are going to put selected object in variable, and then apply transformation to object.

As you can see, we again have anchor point settings, which you can use from first method.

So, what’s different between these two methods? First is easier, and faster, but you can do just one transformation. With second method, you can do multiple transformations at once, and if you repeat same settings again, object will be transformed again. In first method, when we applied rotation twice, nothing happened second time, but with second method, we applied 45 degree rotation, and if we do it again, it will become 90.

I hope that this explanation helped you. Next time we will go through transforming selection with multiple objects.