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

Apply Character direction to textframe characters via Extendscript

Explorer ,
Jun 04, 2024 Jun 04, 2024

Copy link to clipboard

Copied

Hi Folks,

How to apply character direction to TextFrame characters like LEFT_TO_RIGHT_DIRECTION | RIGHT_TO_LEFT_DIRECTION using extendscript.

Thanks in advance 

TOPICS
Bug , How-to , Scripting , Tools

Views

854

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 , Jun 20, 2024 Jun 20, 2024

There have been a few similar topics recently, so I installed the Arabic version of Illustrator to investigate these items.

 

The conclusion is as follows:

/**
  * @File An example of ExtendScript to set paragraph direction and character direction
  * @version 1.0.0
  * @author sttk3.com
*/

(function() {
  var doc = app.documents[0] ;
  var sel = doc.selection[0] ;

  /* Paragraph Direction
  ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION
  ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION
  */
  
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jun 05, 2024 Jun 05, 2024

Copy link to clipboard

Copied

I'm not sure if this is what you're looking for, but you can try it.

 

activeDocument.selection[0].textRange.paragraphDirection = ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION

 

and

 

activeDocument.selection[0].textRange.paragraphDirection = ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION

 

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 ,
Jun 06, 2024 Jun 06, 2024

Copy link to clipboard

Copied

Hi @Sergey Osokin 
Thanks for your reply.

I need to fetch which direction currently the textframe content showing using extendscript and also how to apply these two options using extendscript.

Please check the below two screenshot

right-to-left Character Direction

Screenshot 2024-06-06 at 12.45.26 PM.png

 left-to-right Character Direction 

Screenshot 2024-06-06 at 12.45.14 PM.png

 

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 ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

Hi @Sergey Osokin 
For paragraphDirection ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION its working fine. But ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION not working in illustratror. Please help on this.

Thanks in advance

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
Enthusiast ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

I don't know much about character direction in Illustrator, and I don't have a choice of directions in the Character panel menu like in your screenshots.

SergeyOsokin_0-1718634425628.png

 

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 ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

@Sergey Osokin, where did you get that handy 'js console' plugin?

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
Enthusiast ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

Free extension by Russian developer Marat Shagiev. Marat is also the author of various scripts and other extensions, mainly for the printing industry.

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 ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

Awesome! I looked all

over GitHub to try and find that. Thanks for the link!

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 ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

Thanks for reply

@Sergey Osokin I'm using Arabic version of illustrator. Normal version of illustartor RIGHT_TO_LEFT_DIRECTION working fine. But in Arabic version of illustrator not working. 

 

Note: In Arabic Version of illustrator there is option for paragraph direction and character directions in paragraph and character menu.

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
Enthusiast ,
Jun 20, 2024 Jun 20, 2024

Copy link to clipboard

Copied

Knowing how many problems there are in ExtendScript that Adobe doesn't care about, I'm not surprised that Adobe engineers didn't consider the functionality of the Arabic version of Illustrator for ExtendScript either.

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 ,
Jun 20, 2024 Jun 20, 2024

Copy link to clipboard

Copied

There have been a few similar topics recently, so I installed the Arabic version of Illustrator to investigate these items.

 

The conclusion is as follows:

/**
  * @File An example of ExtendScript to set paragraph direction and character direction
  * @version 1.0.0
  * @author sttk3.com
*/

(function() {
  var doc = app.documents[0] ;
  var sel = doc.selection[0] ;

  /* Paragraph Direction
  ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION
  ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION
  */
  setParagraphDirection(sel.textRange, ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION) ;

  /* Character Direction
  DirOverrideType.DEFAULT_DIRECTION
  DirOverrideType.RIGHT_TO_LEFT_DIRECTION
  DirOverrideType.LEFT_TO_RIGHT_DIRECTION
  */
  sel.textRange.dirOverride = DirOverrideType.RIGHT_TO_LEFT_DIRECTION ;
})() ;

/**
  * Set the paragraph direction. This will succeed even if the specified property is the same as [Normal Paragraph Style]
  * @Param {TextRange} range target text range
  * @Param {ParagraphDirectionType} dstDirection destination paragraph direction
*/
function setParagraphDirection(range, dstDirection) {
  var appliedParagraphStyle = range.paragraphStyles[0] ;
  var styleDirection = appliedParagraphStyle.paragraphDirection ;

  if(styleDirection === dstDirection) {
    var swapMap = {
      'ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION': ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION, 
      'ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION': ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION
    } ;
    appliedParagraphStyle.paragraphDirection = swapMap[dstDirection.toString()] ;
    range.paragraphDirection = dstDirection ;
    appliedParagraphStyle.paragraphDirection = styleDirection ;
  } else {
    range.paragraphDirection = dstDirection ;
  }
}

 

Check the AppleScript scripting dictionary and you will find the properties that can be controlled.

paragraph_direction.png

 

character_direction.png

 

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 ,
Jul 10, 2024 Jul 10, 2024

Copy link to clipboard

Copied

Thanks @sttk3 

Character Direction working properly. 

In Illustrator Arabic Version ParagraphDirectionType.LEFT_TO_RIGHT_DIRECTION working properly. But ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION - ParagraphDirectionType.DEFAULT_DIRECTION not wroking as expected. Please help on this.

Note: Other than Arabic version both ParagraphDirectionType working properly.

Thanks in advance

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

Copy link to clipboard

Copied

LATEST

ParagraphDirectionType.DEFAULT_DIRECTION should not work because the property does not exist.

 

As for ParagraphDirectionType.RIGHT_TO_LEFT_DIRECTION, the result is caused by Illustrator's specification that it is ignored if we set the same property as the paragraph style being applied.

 

The above script has a workaround function setParagraphDirection to avoid this. Instead of just setting the paragraphDirection property, try specifying it via setParagraphDirection.

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