Copy link to clipboard
Copied
How do I access the rotation angle of an object, specifically a group, via script? I've tried BBAccumRotation tag and selectedObject.rotation, but I keep getting errors. I know the value exists in Illustrator as shown in the Properties tab:
I'm trying to write a script that take the rotation value of a selected object and applies the negative of that value to the second selected object.
All help appreciated. Thanks!
I think a group doesn't have a BBAccumRotation tag , but paths within a group do. Assuming that paths within a group will have the same tag, you can access the first one (selection[0] is a selected group):
alert(app.selection[0].pathItems[0].tags[0].name + ": \
" + app.selection[0].pathItems[0].tags[0].value * 180 / Math.PI);
(Courtesy of Silly-V).
Copy link to clipboard
Copied
I think a group doesn't have a BBAccumRotation tag , but paths within a group do. Assuming that paths within a group will have the same tag, you can access the first one (selection[0] is a selected group):
alert(app.selection[0].pathItems[0].tags[0].name + ": \
" + app.selection[0].pathItems[0].tags[0].value * 180 / Math.PI);
(Courtesy of Silly-V).
Copy link to clipboard
Copied
Great! That seems to return a proper value...
Would you be so super kind as to help with the rest of the script? I'm a total scripting hack and while I can generally read what's going on I'm having a hard time getting it to work. This is what I was dealing with previously from ChatGPT:
// Check if a document is open in Illustrator
if (app.documents.length > 0) {
// Get the active document
var doc = app.activeDocument;
// Check if exactly two objects are selected
if (doc.selection.length == 2) {
// Get the first selected object
var selectedObject1 = doc.selection[0];
// Get the rotation angle of the first selected object
var rotationAngle = selectedObject1.rotation;
// Get the second selected object
var selectedObject2 = doc.selection[1];
// Apply opposite rotation angle to the second selected object
selectedObject2.rotate(-rotationAngle);
} else {
alert("Please select exactly two objects in Illustrator.");
}
} else {
alert("Please open a document in Illustrator.");
}
That's the jist of what I'm trying to do. Much appreciated!
Copy link to clipboard
Copied
Note that "the first selected object" refers to the topmost of the two selected objects. (If this doesn't have a rotation tag, an error will occur.) If you want it the other way around, swap the 0 and 1 in doc.selection[0] and doc.selection[1].
// Check if a document is open in Illustrator
if (app.documents.length > 0) {
// Get the active document
var doc = app.activeDocument;
// Check if exactly two objects are selected
if (doc.selection.length == 2) {
// Get the first and second selected objects
var selectedObject1 = doc.selection[0];
var selectedObject2 = doc.selection[1];
// Get the rotation angle of the first selected object
var rotationAngle = selectedObject1.pathItems[0].tags[0].value * 180 / Math.PI;
// Apply opposite rotation angle to the second selected object
selectedObject2.rotate(-rotationAngle);
} else {
alert("Please select exactly two objects in Illustrator.");
}
} else {
alert("Please open a document in Illustrator.");
}
Copy link to clipboard
Copied
!! Awesome! That works great! Thank you so much. This will save me time as this is a often repeated step in a production path for fabric panels I deal with all day =]
One last thing... I noticed that the second object, after being rotated, does not show a rotation value in the properties panel. I usually use this to set the rotation back to zero after applying some other processes to that object. Any idea how to apply the rotation so that it shows as a property?