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

Porting text and text style from one layer to another via expressions

Contributor ,
Apr 27, 2023 Apr 27, 2023

I'm using a "raw" text layer to hold user-entered text, then splitting it by line into "display" layers ("line1" and "line2"). They are basically parsed and stylized versions of the raw. However the text isn't consistently showing correctly on screen, if at all.

 

For example, the following expression in the "line1" layer's sourceText property produces NO text on screen at all:

// Establish base variables
rawText = thisComp.layer("TEXT_RAW").text.sourceText;
layerName = thisLayer.name
lineNum = Number(layerName.charAt(layerName.length-1));
lineIndex = lineNum-1;

// Set the display text for this layer
displayText = rawText.split("\r")[lineIndex];

// Copy font and styling info from Raw Text layer
fontName = rawText.style.font
fontSizeValue =rawText.style.fontSize;
fauxBoldValue = rawText.style.isFauxBold;
fauxItalicValue = rawText.style.isFauxItalic;
allCapsValue = rawText.style.isAllCaps;
smallCapsValue = rawText.style.isSmallCaps;

// Copy any additional attributes that are not customizable by default interface.
strokeWidthValue = thisComp.layer("vars").effect("strokeWidth")("Slider");
strokeColorValue = thisComp.layer("vars").effect("strokeColor")("Color");
fillColorValue = thisComp.layer("vars").effect("baseColor")("Color");

// Access this text layers style object
textStyle = thisLayer.text.sourceText.style

// Apple text styles
textStyle.setText(displayText);
textStyle.setFont(fontName);
textStyle.setFontSize(fontSizeValue);
textStyle.setFillColor(fillColorValue);
textStyle.setFauxBold(fauxBoldValue);
textStyle.setFauxItalic(fauxItalicValue);
textStyle.setAllCaps(allCapsValue);
textStyle.setSmallCaps(smallCapsValue);
textStyle.setStrokeWidth(strokeWidthValue);
textStyle.setStrokeColor(strokeColorValue);

 

 

 

 

Swapping out that last block, "Apply text styles" for a one-liner equivalent DOES produce text on screen. However even in this case the stroke is not applied, color or width. Any ideas?

 

 

// Apple text styles
textStyle.setText(displayText).setFont(fontName).setFontSize(fontSizeValue).setFillColor(fillColorValue).setFauxBold(fauxBoldValue).setFauxItalic(fauxItalicValue).setAllCaps(allCapsValue).setSmallCaps(smallCapsValue).setStrokeWidth(strokeWidthValue).setStrokeColor(strokeColorValue)

 

 

 

TOPICS
Expressions
557
Translate
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 ,
Apr 27, 2023 Apr 27, 2023

I think the last approach is the way to do it, but you need to include a .setApplyStroke() in there.

Translate
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
Contributor ,
Apr 27, 2023 Apr 27, 2023

Thanks yep, .setApplyStroke(true) fixed the 2nd version of the code. 

 

Wondering why it has to be a one-liner though? Doesn't make sense to me. Wouldn't a manipulation of the style object carry over one line to the next? Even chatGPT thought it shoudl work... 

 

Translate
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 ,
Apr 27, 2023 Apr 27, 2023

Generally with expressions, it's the last statement executed that is accepted as the result. My experience with chatGPT-generated code is that its motto must be "when in doubt, just make something up."

Translate
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
Contributor ,
Apr 27, 2023 Apr 27, 2023
LATEST

True, when it's wrong it's confidently wrong. But it was surprisingly helpful until this last point!

Translate
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