• 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 change the alignment of text using javascript?

Explorer ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

Hi,
I need to change the alignment of text to center.

for (var i = 1 ; i <= graphNumberOfLines + 1; i++)

            {

               var ii=i;

               ii= doc.textFrames.add();  //adding text

               ii.textRange.characterAttributes.size = 8;  //character size for text

               ii.textRange.characterAttributes.textFont = app.textFonts.getByName("Times-Roman");

                ii.textRange.StyleRunAlignmentType = "Center";

               ii.top = firstPoint[1]+yGraphInc;  //x coordinate for the new value

               ii.left = firstPoint[0]+xGraphInc;  //y coordinate for the new value

               finalContent=Number(graphFirstValue)+graphIncValue;

               finalContent=finalContent.toString();

               var finalContentcheck=Number(finalContent.indexOf("-"));

               if(finalContentcheck>=0){

                   finalContent=finalContent.replace(/-/g,"–"); 

               }

               ii.contents=(finalContent);  //content for the text frame

               xGraphInc=(xGraphDiff/graphNumberOfLines)*i;  //incrementing the x coordinate

               yGraphInc=(yGraphDiff/graphNumberOfLines)*i;  //incrementing the y coordinate

               if(graphValues[1]>=0){

                    graphIncValue=graphIncValue+graphIncrement;  //incrementing the content

               }else{

                   graphIncValue=graphIncValue-graphIncrement;  //incrementing the content

               }

            }

This is how I am writing in the document. I need to align just after writing.
Thanks in advance.

TOPICS
Scripting

Views

2.6K

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 , Apr 16, 2018 Apr 16, 2018

Hi,

and again - it is really better if you don't use ii as variable name!

Try:

theEvilNameOfYourOwnVariable.textRange.justification = Justification.CENTER;

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

Hi,

and again - it is really better if you don't use ii as variable name!

Try:

theEvilNameOfYourOwnVariable.textRange.justification = Justification.CENTER;

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 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Wow that worked... Thank-you

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 Beginner ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

LATEST

Does anyone know how to vertically align text to the centre with a script? In the Illustrator properties dialog for a text box, we find horizontal alignment under "Paragraph," and vertical alignment under "Area Type." I do not know the equivalent property and object parents in JavaScript to accomplish exactly this; yet, it must be done, as I wish to insert measurement legends at the proper place in my diagrams.

 

So for horizontal:

  myText.textRange.justification = Justification.CENTER;

 

And for vertical:

  ???

 

We are not going to find it in textRange because there could be many of these with their own horizontal alignments, and only one vertical alignment is applicable for the text box.

 

 

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
People's Champ ,
Apr 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/pixxxel+schubser  a écrit

and again - it is really better if you don't use ii as variable name!

He he maybe it's a des-ii-gn pattern we don't know of

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