Skip to main content
Known Participant
May 21, 2023
Question

Help with addText()

  • May 21, 2023
  • 1 reply
  • 638 views

I'm passing to addText() a TextDocument from an existing text layer with some modifications. The modified text itself is passed, but other properties, like font and fillColor are not passed. Instead, the current font and fill color in the Character panel are set. Am I doing something wrong? Do I have to manually set every property after the fact?

 

let selectedLayer = app.project.activeItem.selectedLayers[0];
let sourceDocProp = selectedLayer.sourceText;
let sourceTextDoc = sourceDocProp.value; 

let newTextDoc = sourceTextDoc;
newTextDoc.text = "Changed text";
newTextDoc.fillColor = [0,0,0];
newTextDoc.font = "Arial";

let newTextLayer: TextLayer = app.project.activeItem.layers.addText(newTextDoc);

 

This topic has been closed for replies.

1 reply

Known Participant
May 21, 2023

May have answered my own question. Seems like addText() is only accessing the text property of the TextDocument. I have to run setValue() and pass the TextDocument a second time to update everything else.

let newTextLayer: TextLayer = app.project.activeItem.layers.addText(newTextDoc); // Sets just the text
const newTextLayerDocProp = newTextLayer.sourceText;
newTextLayerDocProp.setValue(myTextDoc); // Sets all the other text properties.
Mathias Moehl
Community Expert
Community Expert
May 21, 2023

The documentation of addText says that it supports both a string or a TextDocument:

https://ae-scripting.docsforadobe.dev/layers/layercollection.html#layercollection-addtext

If it ignores all additional properties of the TextDocument, this sounds like a bug and I recommend that you report it. Good that you found a workaround 🙂

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Known Participant
May 22, 2023

Yeah, I also interpreted the documentation that way! I'll file a bug report. Thanks.