-
Trying to use ScriptUI to style a text layer
I have simple ScriptUI button that creates a 4 digit timecode and places it in the bottom left of any size comp.
It works, but with a problem – I’m unable to style the text in any way, so it always ends up taking on the style of the last used piece of text.
I want to use the Monaco font (and if possible: 40px size, white fill, black outline 10px, All Fills Over All Strokes). The block of code below (the part concerning styling) is pasted (and slightly adapted) from page 182 of the Adobe CS6 Scripting guide. The only style that seems to have any effect is ParagraphJustification.
Any help would be appreciated.
myPanel.grp.group14.timeCodeButton.onClick = function() {var text = app.project.activeItem.layers.addText();
app.project.activeItem.layer(1).text.sourceText.expression = "Numbers = 4; t =timeToFrames(time); c = t.toString().length; while( c < Numbers){ t = \"0\"+t; c++ } t";
app.project.activeItem.layer(1).position.expression = "[20,thisComp.height-20]";var textProp = text.property("Source Text");
var textDocument = textProp.value;
myString = "Timecode";
textDocument.resetCharStyle();
textDocument.fontSize = 40;
textDocument.fillColor = [1, 0, 0];
textDocument.strokeColor = [0, 1, 0];
textDocument.strokeWidth = 2;
textDocument.font = "Monaco";
textDocument.strokeOverFill = false;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.LEFT_JUSTIFY;
textDocument.tracking = 50;
textProp.setValue(textDocument);
}