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

How to access rotation angle of group via scripting

Explorer ,
Apr 29, 2024 Apr 29, 2024

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:

 

Screenshot 2024-04-29 at 11.22.29.jpg

 

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!

 

 

TOPICS
How-to , Scripting

Views

394

Translate

Translate

Report

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 , Apr 29, 2024 Apr 29, 2024

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

Votes

Translate

Translate
Adobe
Guide ,
Apr 29, 2024 Apr 29, 2024

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

Votes

Translate

Translate

Report

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
Explorer ,
Apr 29, 2024 Apr 29, 2024

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!

Votes

Translate

Translate

Report

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 ,
Apr 30, 2024 Apr 30, 2024

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.");
}

 

Votes

Translate

Translate

Report

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
Explorer ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

LATEST

!! 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?

Votes

Translate

Translate

Report

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