ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trying to use ScriptUI to style a text layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mark Paterson
Trying to use ScriptUI to style a text layer
on Dec 7, 2019 at 9:04:58 pm

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 &lt; 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);
}




Return to posts index

Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 7, 2019 at 9:09:24 pm

The original styling code is also available at http://docs.aenhancers.com/other/textdocument 3rd example from top. I've tried that same code and it still doesn't work.

Also, I'm 99% sure that the PostScript name of the font is "Monaco" (according to Apple Font Book), which is a requirement of textDocument.font



Return to posts index

Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 7, 2019 at 9:18:34 pm

I've also tried running the script (below) as a JSX using File > Scripts > Run Script File.

This time it's exactly the same as the Adobe Scripting Guide one (as both "TimesNewRomanPSMT" and "Times New Roman PSMT". Same issue - the text appears, but it's still not styling anything!

var text = app.project.activeItem.layers.addText();

var textProp = text.property("Source Text");
var textDocument = textProp.value;
myString = "Happy holidays!";
textDocument.resetCharStyle();
textDocument.fontSize = 60;
textDocument.fillColor = [1, 0, 0];
textDocument.strokeColor = [0, 1, 0];
textDocument.strokeWidth = 2;
textDocument.font = "TimesNewRomanPSMT";
textDocument.strokeOverFill = true;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;
textDocument.tracking = 50;
textProp.setValue(textDocument);




Return to posts index


Tomas Bumbulevičius
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 1:58:34 pm

Mark, I remember facing similar issues in the past, but don't remember what caused it!

Despite of that - try hiding 'textDocument.resetCharStyle();' and see if it helps. I have a sense that this was an issue, which reset to system default and then didn't worked from there. Please let us know!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 5:21:14 pm

Hiding that line has no effect I'm afraid. ☹

At this point I'm focusing on the script below (removing my Timecode parts). It's based solely on the Adobe Scripting Guide version, and running it from the File menu. This way I can at least see error codes (vs Script UI where in most cases I do not).

I've changed a couple of values to make any changes obvious (font size, tracking), so even if I have the font name wrong, then surely the other changes would be apparent. Currently none of these changes actually change anything. Only thing I can control below is the paragraph justification.

var text = app.project.activeItem.layers.addText();
var textProp = text.property("Source Text");
var textDocument = textProp.value;
myString = "Happy holidays!";
textDocument.resetCharStyle();
textDocument.fontSize = 300;
textDocument.fillColor = [1, 0, 0];
textDocument.strokeColor = [0, 1, 0];
textDocument.strokeWidth = 2;
textDocument.font = "TimesNewRomanPSMT";
textDocument.strokeOverFill = true;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;
textDocument.tracking = 200;
textProp.setValue(textDocument);




Return to posts index

Dan Ebberts
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 7:30:07 pm

I don't understand it, but it seems to work if you set the value twice:

textProp.setValue(textDocument);
textProp.setValue(textDocument);


Dan



Return to posts index


Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 8:11:22 pm

WOW. That is truly bizarre. Thanks so much for figuring it out, I was really pulling my hair out!!

Is there a way to specify All Strokes Over All Fills? I don't see anything for it at http://docs.aenhancers.com/other/textdocument perhaps it is undocumented?

I've tried textDocument.allFillsOverAllStrokes = true;



Return to posts index

Dan Ebberts
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 8:19:19 pm

>Is there a way to specify All Strokes Over All Fills?

Not that I'm aware of.


Dan



Return to posts index

Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 8:27:21 pm

ok, no big deal. A minor inconvenience I can live with by adjusting the stroke and tracking slightly to compensate.

Thanks again, Dan. As a motion designer, I've lurked on this forum over the years and noted your many contributions. I've only started posting recently since deciding once and for all to learn Javascript/Extendscript, so it's nice to get a problem solved by the man himself haha.

For anyone out there who's interested in the final working script – this will add a 4 digit frame timecode to the bottom left of any size comp. You can execute this as a script or via a Script UI button.

app.project.activeItem.layer(1).text.sourceText.expression = "Numbers = 4; t =timeToFrames(time); c = t.toString().length; while( c &lt; Numbers){ t = \"0\"+t; c++ } t";
app.project.activeItem.layer(1).position.expression = "[10,thisComp.height-13]";

var textProp = text.property("Source Text");
var textDocument = textProp.value;
myString = "Timecode";
textDocument.resetCharStyle();
textDocument.fontSize = 40;
textDocument.fillColor = [1, 1, 1];
textDocument.strokeColor = [0, 0, 0];
textDocument.strokeWidth = 8;
textDocument.font = "Monaco";
textDocument.strokeOverFill = false;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.LEFT_JUSTIFY;
textDocument.tracking = 45;
textProp.setValue(textDocument);
textProp.setValue(textDocument);




Return to posts index


Mark Paterson
Re: Trying to use ScriptUI to style a text layer
on Dec 8, 2019 at 8:37:46 pm

Oops. Made a copy / paste goof and unable to edit my post. There should also be a line at the top to create a text layer first. Amended script below.

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 &lt; Numbers){ t = \"0\"+t; c++ } t";
app.project.activeItem.layer(1).position.expression = "[10,thisComp.height-13]";

var textProp = text.property("Source Text");
var textDocument = textProp.value;
myString = "Timecode";
textDocument.resetCharStyle();
textDocument.fontSize = 40;
textDocument.fillColor = [1, 1, 1];
textDocument.strokeColor = [0, 0, 0];
textDocument.strokeWidth = 8;
textDocument.font = "Monaco";
textDocument.strokeOverFill = false;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.LEFT_JUSTIFY;
textDocument.tracking = 45;
textProp.setValue(textDocument);
textProp.setValue(textDocument);




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]