Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 🙂
Copy link to clipboard
Copied
Yeah, I also interpreted the documentation that way! I'll file a bug report. Thanks.