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

[ ExtendScript ] How to rotate a text frame properly? Just like the GUI does it.

Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Hi together,

you might think it's the simplest thing to do using method rotate() on a selected text frame.

But somehow I cannot do this exactly like the GUI is doing this with the Transform panel.

 

Simple code:

app.activeDocument.selection[0].rotate( 20 );

 

Or if one likes to use a rotation matrix:

var rotationMatrix = app.getRotationMatrix( 20 );
app.activeDocument.selection[0].transform( rotationMatrix );

 

Here the result when doing this in the GUI, the new rotation angle is visible in the Transform panel of my German Illustrator 26.3.1 on Windows 10:

 

GUI-Rotate 20° CCW.PNG

 

When I'm doing this with the code above, the "bounds" are not rotated, still there is value 0 in the rotation entry field of the Transform panel; the text contents is rotated like that:

 

SCRIPT-Rotate 20° CCW.PNG

 

What can I do to get the same result that I can get with the GUI?

 

Thanks,
Uwe Laubender
( Adobe Community Professional )

TOPICS
Scripting

Views

838

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

Community Expert , May 23, 2022 May 23, 2022

From what I have found, script does not seem to update the tag "BBAccumRotation" in the text frame.

 

When I updated it on my own, I got the same result as when I did it in the GUI.

 

rotateItem(app.activeDocument.selection[0], 20) ;

/**
  * rotate item and write rotation angle in tag
  * @Param {PageItem} targetItem pageItem
  * @Param {Number} angle rotation angle in degrees
  * @Return {}
*/
function rotateItem(targetItem, angle) {
  targetItem.rotate(angle) ;
  
  // writes rotation angle (in r
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

From what I have found, script does not seem to update the tag "BBAccumRotation" in the text frame.

 

When I updated it on my own, I got the same result as when I did it in the GUI.

 

rotateItem(app.activeDocument.selection[0], 20) ;

/**
  * rotate item and write rotation angle in tag
  * @Param {PageItem} targetItem pageItem
  * @Param {Number} angle rotation angle in degrees
  * @Return {}
*/
function rotateItem(targetItem, angle) {
  targetItem.rotate(angle) ;
  
  // writes rotation angle (in radians) to tags['BBAccumRotation']
  var tagName = 'BBAccumRotation' ;
  var rad = angle * (Math.PI / 180) ;
  try {
    var rotationInfo = targetItem.tags[tagName] ;
    rotationInfo.value = (Number(rotationInfo.value) + rad).toString() ;
  } catch(e) {
    var rotationTag = targetItem.tags.add() ;
    rotationTag.name = tagName ;
    rotationTag.value = rad.toString() ;
  }
}

 

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
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Hi sttk3,

thank you very much for this!

Just tested and all looks very good.

 

Never thought, that it would be necessary to update or add a tag like "BBAccumRotation" to a page item.

Usually I am writing scripts for InDesign where something like that is not necessary; when I think about the concept alone, well, I'm a little speechless…

 

Your solution is working. And I will look deeper into the possible applications of tags for page items.

Right now it seems to be a weird concept for me.

 

Thanks,
Uwe Laubender
( Adobe Community Professional )

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
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

@Laubender wrote:

Usually I am writing scripts for InDesign where something like that is not necessary; when I think about the concept alone, well, I'm a little speechless…

 

Hi Uwe, so we have come to the dinner party and met with Indesign's cousin, Illustrator, who forgot to wear pants to the table. I am a little speechless too... but I love them both all the same. Haha.

 

On a serious note, this "BBAccumRotation" issue is rare to come up in practice. Off the top of my head I don't think tags are used for anything else. Perhaps worse is the dirty namespace issues. For example, "selection" is the same as "app.activeDocument.selection" for example, so in Illustrator we must avoid giving variables names like path or selection due to this mess.

 

About the old Illustrator Scripting Forum: just raise a topic here with Scripting tag. It can go as deep as we like it to. There are people here who really know their stuff—like @sttk3 as you can see! 🙂

- Mark

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
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

On a second thought, the concept behind tags is like InDesign's keystring/valuestring concept for the old DPS module.

A different attitude to expand the DOM compared to object property/value pairs.

( Oh, how I'd love to have an Illustrator Scripting Forum back where we can discuss concepts like that more deeply. )

 

Thanks,
Uwe Laubender
( Adobe Community Professional )

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
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

sttk3 said: "From what I have found, script does not seem to update the tag "BBAccumRotation" in the text frame."

 

Would you categorize this behavior as a bug?

 

Regards,
Uwe Laubender
( Adobe Community Professional )

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
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

"BBAccumRotation" is an informal property that is often referenced to get the rotation angle of a TextFrame. Its lack of support does not amount to a bug. I am rather surprised that it affects the behavior in the GUI.

 

It might have been better to limit the target from PageItem to TextFrame. Normally one is rarely aware of tags when editing a PageItem.

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
Community Expert ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

LATEST

Shame on me, I totally forgot about my previous experiments with that tag "BBAccumRotation" in April 2019:

https://community.adobe.com/t5/illustrator-discussions/adobe-illustrator-tags/m-p/6860290#M152586

 

Back then I said: "Never trust the value of BBAccumRotation".

Have to investigate if that's still true with newer versions of Illustrator.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

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