• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Struggling to understand TextDocument (want to format text layer)

Explorer ,
Aug 17, 2016 Aug 17, 2016

Copy link to clipboard

Copied

Hi everybody,

I've spent a ton of time trying to understand how textDocument works, but I just can't seem to wrap my mind around it.  

In the script I'm working on, I take text entered into an edittext box, then split it up by word, entering it into an array.  I add it to the comp, one word per layer.  I'd like to be able to pick the font size and color before it creates these layers. 

Here is the function that responds to a button click:

buttonCreate.onClick = function () {

            var stringArray = myEditText.text.split(" ");

            var stringArrayNumItems = stringArray.length;

           

            //Loop through stringArray words

            for(i=0;i<stringArrayNumItems;i++) {

                curComp.layers.addText(stringArray);

               

            }

           

        }

So, I know I need to put that line that includes .addText in it into a variable.  I just don't know how to go through and edit its properties. 

Thanks!

-Justin

TOPICS
Scripting

Views

483

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Aug 17, 2016 Aug 17, 2016

var curComp = app.project.activeItem; //Assumes the activeItem is a CompItem

if(curComp instanceof CompItem){//Makes sure that it is a CompItem

  var myTextLayer = curComp.layers.addText("Initial text layer creation");//Creates the text layer

  var textProp = myTextLayer.property("Source Text");//Assigns the text layer source text property to a variable

  var textDocument = textProp.value;//Gets the source text property value

  //Begin assigning each text layer related attribute to the textDocument v

...

Votes

Translate

Translate
Advocate ,
Aug 17, 2016 Aug 17, 2016

Copy link to clipboard

Copied

var curComp = app.project.activeItem; //Assumes the activeItem is a CompItem

if(curComp instanceof CompItem){//Makes sure that it is a CompItem

  var myTextLayer = curComp.layers.addText("Initial text layer creation");//Creates the text layer

  var textProp = myTextLayer.property("Source Text");//Assigns the text layer source text property to a variable

  var textDocument = textProp.value;//Gets the source text property value

  //Begin assigning each text layer related attribute to the textDocument variable

  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;

  //Apply all that data to your already created textLayer source text property

  textProp.setValue(textDocument);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2016 Aug 17, 2016

Copy link to clipboard

Copied

LATEST

Thank you so much.  This was the breakdown I was looking for!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines