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.
1 Correct answer
Hi,
and again - it is really better if you don't use ii as variable name!
Try:
theEvilNameOfYourOwnVariable.textRange.justification = Justification.CENTER;
Explore related tutorials & articles
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;
Copy link to clipboard
Copied
Wow that worked... Thank-you
Copy link to clipboard
Copied
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.
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

