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

ExtendScript changes text area line count; now will not center text

Explorer ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

Thanks in advance for your help with this:

I have a comp with a Text Area with 5 lines of English placeholder text in the project. The text layer is centered over a shape layer.

 

When my ExtendScript replaces the 5 English lines with its Russian translation, which is 6 lines, the Text Area grows horizontally … at the bottom; now the text is no longer horizontally centered over the shape.

 

To fix this centering issue, I have the following script for the “Anchor Point”: 

s=sourceRectAtTime();[0,s.top+s.height/2]+value; 

Works beautifully as you can see. BUT: the paragraph alignment, which was set to “Center Text” somehow gets changed to “Left Align Text” (red rectangle)!

Even if I force alignment after changing the text with :

 

textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;

 

Makes no difference, the text remains left justified.

Abbreviated code:

 

 

for (var gg = 1; gg <= numLayers; gg++) {
    if (app.project.item(y).layer(gg).property("Source Text") !== null) { 
   
        replaceText =  (4 lines of text from a JSON file)

        app.project.item(y).layer(gg).property("Source Text").setValue(replaceText); // replaceText with the 4 lines

        textProp = app.project.item(y).layer(gg).property("Source Text");
        textDocument = textProp.value;    
 
        textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;     //   Force Center Justify 
    }
}

 

 CenteringIssue.png

TOPICS
Expressions , Scripting

Views

691

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

Enthusiast , Apr 15, 2021 Apr 15, 2021

Yes I've used that same solution of breaking up the steps myself. As I wrote it untested I was a bit worried you might run into some issue. AE scripting has plenty of quirks/bugs you have to find workarounds for. Glad you got it figured out.

I wrote it that way to show you the alternate way to set the text string but you can probably simplify it to this:

textProp.setValue(replaceText);

textDocument = textProp.value;    
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY; 
textProp
...

Votes

Translate

Translate
Enthusiast ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

The problem is that your script isn't actually setting the justification. When you read the 'value' of the TextDocument object, think of it like making it separate copy rather than a live link. So once you've made changes to that copy you need to set it back onto the SourceText property. SourceText is kinda odd in that you can either set its value using just a string to change the text or a textDoc object to change everything.

 

for (var gg = 1; gg <= numLayers; gg++) {
    if (app.project.item(y).layer(gg).property("Source Text") !== null) { 
   
        replaceText =  (4 lines of text from a JSON file);

        textProp = app.project.item(y).layer(gg).property("Source Text");
        textDocument = textProp.value;    
 
        textDocument.text = replaceText;
        textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;     //   Force Center Justify 
		
        textProp.setValue(textDocument);
    }
}

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 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Thank you for your quick response Paul, it’s much appreciated! 

I tried your suggestion, but with no success.  Even if I replaced the text with the exact same text.

I removed the expression that re-centers the Anchor Point, in case this was somehow causing a problem – ya never know – but that did not fix the issue.

But I noticed something: while the script was running, I could briefly see the Russian text nicely center justified … and then suddenly, it became left justified. Hmmm.

I modified the script to apply the two changes in two steps instead of one, like in the snippet and now it works!

textDocument = textProp.value;    
textDocument.text = replaceText;		
textProp.setValue(textDocument);

textDocument = textProp.value;    
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY; 
textProp.setValue(textDocument);

 

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 ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Yes I've used that same solution of breaking up the steps myself. As I wrote it untested I was a bit worried you might run into some issue. AE scripting has plenty of quirks/bugs you have to find workarounds for. Glad you got it figured out.

I wrote it that way to show you the alternate way to set the text string but you can probably simplify it to this:

textProp.setValue(replaceText);

textDocument = textProp.value;    
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY; 
textProp.setValue(textDocument);

 

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 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

LATEST

I can certainly confirm that there are many quirks and idiosyncrasies in the ExtendScript/AE world -for SURE!  This has been quite the 10 month adventure. I haven’t developed or coded in over 20 years and my first project involved  quite the stack! But this CEP part was the most difficult. The documentation is spoty, especially for AME; EG from the AME DG:

2.2.8 app.getWatchFolder()*

app.getWatchFolder() *untested

Parameters

unknown

Returns

unknown

I appreciate your help. Without this forum and “NT Productions” over on YouTube, I may have had to capitulate, but now, I'm into final testing.

 

Cheers

Roland

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