Trying to use ScriptUI to create a text layer and then style it. Can't do either!
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 few problems…
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]";
The first problem is I can't figure out how to create a text layer automatically, at the start of this script. So I have to manually create the text layer myself (who has time for that? haha).
To create the text layer with scripting i've tried this at the top of the script…
app.project.item(index).layers.addText(sourceText);
or…
app.project.activeItem.layer(1).addText(sourceText);
but neither work. Neither does calling the exact command ID number which is apparently 7028 or 7058. Neither of the numbers do anything (but they may be out of date, is there a more current list somewhere?).
The second problem is I'm unable to style the text in any way, so it always ends up taking on the style of the last used peice of text. I want to use the Monaco font (and if possible: 40px size, white fill, black outline 10px, All Fills Over All Strokes). I've tried…
textDocument.font = "Monaco";
According to Apple's Font Book, this is the correct PostScript name. But this line on it's own does nothing. I assume it might need to be added to the object path, however this doesn't work either…
app.project.item(index).layers.textDocument.font = "Monaco";
