Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions SourceText TextDocument keyframes read incorrectly when layer is moved in time

  • SourceText TextDocument keyframes read incorrectly when layer is moved in time

    Posted by Mark Fain on June 29, 2022 at 1:20 pm

    I am trying to read through the sourceText keyframe values to later change a specified font which may or may not exist on those keys. This code works wonderfully before I drag the text layer left or right on the timeline. It continues to work when I move the sourceText keyframes or drag just the in/outPoint of the text layer. It’s only when I actually move the whole layer with the keys that it changes the font values of the keys even though the correct fonts show in the Comp and Character window.

    For example, if I have 5 keyframes with 5 different fonts with the text layer in its default position, the keys’ font values get read correctly, but if I drag the whole text layer past where the 5th keyframe was originally, all 5 keys will read as the original font value of that 5th keyframe.

    How do I make sure text layers that aren’t in their default positions have their sourceText keys read properly?

     

    var sourceTextProps = [];

    var textDocs = [];

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

    sourceTextProps[i]=textLayers[i].sourceText;

    if (sourceTextProps[i].numKeys > 0) {

    for (var keyIndex = 1; keyIndex <= sourceTextProps[i].numKeys; keyIndex++) {

    textDocs.push(sourceTextProps[i].keyValue(keyIndex));

    }

    }

    }

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

    alert (textDocs[i].font )

    }

    
    
    
    

     

     

     

    
    				
    Dan Ebberts
    replied 4 years, 2 months ago
    2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    June 29, 2022 at 3:37 pm

    I get the same result. This looks like a bug to me. I’m not sure how you can work around it. (I’ve reported it to Adobe).

  • Mark Fain

    June 29, 2022 at 5:41 pm

    Thank you, Dan, for this and for everything. I was definitely asking why they’d want it to function that way.

    In the meantime, I’m going to try to work around it by getting key times and resetting values based on time…or something like that. I have some experimenting to do. I’ll be back if anything starts to look viable.

  • Dan Ebberts

    June 29, 2022 at 5:46 pm

    Yes, please report back if you find anything. I tried valueAtTime() with keyTime() and it didn’t help, but maybe you’ll figure something out.

  • Mark Fain

    June 29, 2022 at 9:52 pm

    Well, I didn’t find a solution, but I found that FontMate has the same problem haha.

  • Mark Fain

    June 30, 2022 at 5:01 am

    Got it. Using time-based values instead of key-based values, I could offset where it reads the values by subtracting the layers’ startTime from each keyTime.

    if (sourceTextProps[i].numKeys > 0) {

    offsetTimes[i] = textLayers[i].startTime;

    for (var keyIndex = 1; keyIndex <= sourceTextProps[i].numKeys; keyIndex++) {

    keyTimes[i] = sourceTextProps[i].keyTime(keyIndex) - offsetTimes[i];

    textDocs.push(sourceTextProps[i].valueAtTime(keyTimes[i], null));

    }

    }

    Then later, when I’m setting values:

    sourceTextProps[i].setValueAtTime(keyTimes[i] + offsetTimes[i], tD[i]);

  • Mark Fain

    June 30, 2022 at 5:22 pm

    Actually, an even better way without all the time math is just to store the startTime in a variable, set the startTime of the layer to 0, do all your stuff, then set it back to the original time variable. The code below would be in a for loop to do this on each text layer.

    var theLayer = textLayers[i];

    var theSourceProp=theLayer.sourceText;

    var originalTime = theLayer.startTime;

    if (originalTime != 0) {

    theLayer.startTime = 0;

    }

    if (theSourceProp.numKeys > 0) {

    for (var keyIndex = 1; keyIndex <= theSourceProp.numKeys; keyIndex++) {

    textDocs.push(theSourceProp.keyValue(keyIndex));

    }

    }

    else if (theSourceProp.numKeys == 0) {

    textDocs.push(theSourceProp.value);

    }

    theLayer.startTime = originalTime;

  • Dan Ebberts

    July 1, 2022 at 12:15 am

    I like that better, because it should still work, even if they fix the bug. Good sleuthing!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy