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

Breaking text up into layers from source.txt - mostly working but need a little help

New Here ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Hello,

Here's the situation - I've been brought into the middle of project that involves creating Comps which contain 1 or more type layers horizontally aligned into a single line of type which scrolls left to right. The source for the text comes from text files, 1 text file per Comp. Essentially they are famous quotes or short passages with an author at the end. The type style, canvas size, default type size and other info comes from the script using a template comp. It also attaches a couple different sliders to change the scale of the font or its scrolling speed, but in this case they don't seem to be needed. It also sets the work area of the comp file it creates to the length of the animated scrolling text. 

There are several hundred text files/comps that need(ed) to be created. I was handed off a script that would do this one text file/comp at a time. Obviously that was going to be a lot of tedious work to execute one at a time. I was able to take the script and replace it looking for a text file with the ability to be pointed at a folder, where it moves through the files in one long, looping process.

However I'm working quickly on somewhat tight timeline so I didn't want to change anything I didn't have to. I've run the script and as I said it processed most of what I need to, except for a few exceptions where it hit some problems. I guess if anyone can help me work out why this script works the way it does, and how I could make it a little more flexible, that would be fantastic. I can hack things together ok, but I'm not very experienced at scripting. 

I've tried looking for examples of other scripts working this way, but I haven't found anything that handles this process in this manner. There isn't anything in the comments either, so if any of you recognize it or know where it came from I'll happily credit the original author in the source.

 

This is already a long post so here's the main part without the file reading and such... As I said, its reading in files from folders and everything fine after I modified a few things, like emptying out some variables that weren't meant to loop.

    for (var i = 0; i < phrases.length; i++) {

      myNextPhrase = phrases;

      myLayer.text.sourceText.setValue(myNextPhrase + ".");

      tempRect = myLayer.sourceRectAtTime(0, false);

      nextPhraseLen = vert ? tempRect.height : tempRect.width;

      if (curLen + nextPhraseLen > longPhraseMax) {

        longPhrases[longPhrases.length] = myLongPhrase;

        myLongPhrase = myNextPhrase;

      } else {

        myLongPhrase += myNextPhrase;

      }

      myLayer.text.sourceText.setValue(myLongPhrase + ".");

      tempRect = myLayer.sourceRectAtTime(0, false);

      curLen = vert ? tempRect.height : tempRect.width;

    }

    if (myLongPhrase.length > 0) {

      longPhrases[longPhrases.length] = myLongPhrase;

    }

    for (var i = 1; i < longPhrases.length; i++) {

      myLayer.duplicate();

    }

    var tempTextDoc;

    var tempTextLen;

    var mySlider1;

    var mySlider2;

    var blankCount;

    var blankIdx;

    var tempLongPhrase;

    var totalWidth = 0;

    for (var i = 1; i <= longPhrases.length; i++) {

      myLayer = myComp.layer(i);

      // temporarily replace ending blanks with printing character

      blankCount = 0;

      blankIdx = longPhrases[i - 1].length - 1;

      while ((longPhrases[i - 1][blankIdx] == " ") && (blankIdx >= 0)) {

        blankCount++;

        blankIdx--;

      }

      tempLongPhrase = longPhrases[i - 1].substr(0, longPhrases[i - 1].length - blankCount);

      for (var j = 1; j <= blankCount; j++) {

        tempLongPhrase += "^";

      }

      myLayer.text.sourceText.setValue(tempLongPhrase);

      tempTextDoc = myLayer.text.sourceText.value;

      tempTextLen = tempTextDoc.text.length;

      tempRect = myLayer.sourceRectAtTime(0, false);

      mySlider1 = myLayer.property("Effects").property("**** internal 1");

      mySlider2 = myLayer.property("Effects").property("**** internal 2");

      if (vert) {

        mySlider1.property("ADBE Slider Control-0001").setValue(tempRect.top);

        mySlider2.property("ADBE Slider Control-0001").setValue(tempRect.height);

        totalWidth += tempRect.height + 1;

      } else {

        mySlider1.property("ADBE Slider Control-0001").setValue(tempRect.left);

        mySlider2.property("ADBE Slider Control-0001").setValue(tempRect.width);

        totalWidth += tempRect.width + 1;

      }

      myLayer.text.sourceText.setValue(longPhrases[i - 1]);

    }

var myScale;

    if (vert) {

      myScale = myComp.layer(1).property("Scale").valueAtTime(0, false)[1];

    } else {

      myScale = myComp.layer(1).property("Scale").valueAtTime(0, false)[0];

    }

    var myPPF = myComp.layer(1).property("Effects").property("Pixels Per Frame").property("ADBE Slider Control-0001").value;

    var myDur = ((totalWidth * Math.abs(myScale) / 100 + myComp.width) / myPPF + 2) * myComp.frameDuration;

    if (myDur > myComp.duration - 2) {

      myDur += 2;

      myComp.duration = myDur;

      for (var i = 1; i <= myComp.numLayers; i++) {

        myComp.layer(i).outPoint = myDur;

      }

    }

    myComp.workAreaStart = 0;

    myComp.workAreaDuration = myDur;

 

When it does get stuck, its here at  "myComp.workAreaDuration = myDur; " where it hits the max allowed. I'm not entirely sure about everything it's doing, since I'm coming into this a little late in the pipeline. I think I get the gist of what its doing breaking type into word chunks and putting them together into rectangles, but I don't get the upper bounds. If anyone can break it down a little for me or better yet can see why it might have issues with long files, then please let me know. Again I don't know what this was being used for originally or where it came from so I'm not sure whats needed.

Thanks!

TOPICS
Scripting

Views

300

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
Enthusiast ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

LATEST

After Effects has a limitation in the composition duration and it's 3 hours.

Make sure that you don't break it.

P.S. there is no workaround to break it.

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