Copy link to clipboard
Copied
I got a problem with the rotate function. When I rotate an (text) object (point text but same behavior with area text) on the GUI of Illustrator, the resize bounds around (see screenshot) is rotated as well so that you can resize it as used to. If I rotate the same object by JavaScript, the resize bounds are NOT rotated along with. How can I get the same effect as with the GUI-way by JavaScript as thats the result I need? And where is my thinking error. Here is the code I used for the rotation:
var docRef = app.activeDocument;
var sRef = docRef.selection[0];
sRef.rotate(20, true, true, true, true, Transformation.TOPLEFT);
after some tinkering, i think i perhaps have found a solution for the bounding box issue. The way we can keep it, is by also adding tags. I tried using them seperate, but adding tags by themselves doesnt work. Thats why i run the rotate function as well.
I first got that tags name by running it on an object which had rotation. first i though what a weird name, but BB probably stands for BoundBox
var doc = app.activeDocument;
if (app.documents.length > 0) {
for (var i =
...
Copy link to clipboard
Copied
Hi Jens, I had the same problem, no matter what I tried, rotating via scripting keeps resetting the bounding box. I resolved it by recording an action to rotate the object, same results as if rotated manually. If you still need to rotate via scripting, VBS and AppleSript can execute Actions from script, JS can not.
Copy link to clipboard
Copied
Hello CarlosCanto, thats bad news because I cant use an action as the angle to rotate the objekt ist determinend at runtime ... as well as I have to use javascript for the integration of several scripts together ...
Copy link to clipboard
Copied
after some tinkering, i think i perhaps have found a solution for the bounding box issue. The way we can keep it, is by also adding tags. I tried using them seperate, but adding tags by themselves doesnt work. Thats why i run the rotate function as well.
I first got that tags name by running it on an object which had rotation. first i though what a weird name, but BB probably stands for BoundBox
var doc = app.activeDocument;
if (app.documents.length > 0) {
for (var i = 0; i < doc.selection.length; i++) {
var ob = doc.selection[i]
tags = ob.tags;
tags.add()
ob.tags[0].name = "BBAccumRotation"
var pi = Math.PI;
// var degrees * (pi/180);
// ob.tags[0].value = (10* 180 / Math.PI)
ob.tags[0].value = 10* (pi/180);
ob.rotate(ob.tags[0].value * 180 / Math.PI, true)
}
}
I quickly made a screengrab showing the difference. This was for a script replace objects with a symbol and also apply rotation. I wanted to keep how the boundingbox shows, thats why it doesnt show with either transformation matrix or rotate function
Copy link to clipboard
Copied
Hi @schroef , it seems to work! great find, thanks for sharing
Copy link to clipboard
Copied
I bumped into this, using transformationMatrix. This actually keeps the rotation
This is the example of Adobe help docs
// Tranforms all art in a document using translation and rotation matrices,
// moves art half an inch to the right and 1.5 inches up on the page
if (app.documents.length > 0) {
var moveMatrix = app.getTranslationMatrix(0.5, 1.5);
// Add a rotation to the translation, 10 degrees counter clockwise
var totalMatrix = concatenateRotationMatrix(moveMatrix, 10);
// apply the transformation to all art in the document
var doc = app.activeDocument;
for (var i = 0; i < doc.pageItems.length; i++) {
doc.pageItems[i].transform(totalMatrix);
}
}
Found here; https://ai-scripting.docsforadobe.dev/jsobjref/Matrix.html
Copy link to clipboard
Copied
Its seems it doesnt always work. on pathItems it seems to work. With symbols. the boundingbox seems to get reset again