Skip to main content
Known Participant
April 27, 2023
質問

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

  • April 27, 2023
  • 返信数 1.
  • 724 ビュー

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)

 

 

 

このトピックへの返信は締め切られました。

返信数 1

Dan Ebberts
Community Expert
Community Expert
April 27, 2023

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

Known Participant
April 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... 

 

Dan Ebberts
Community Expert
Community Expert
April 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."