Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Limiting a text editing script to a range of characters

  • Limiting a text editing script to a range of characters

    Posted by Sergio Pol on August 8, 2015 at 2:31 am

    Hello there I created this script with great help from Dan Ebberts some months ago. It changes the font style of a selected text layer in regular intervals. It’s a very useful script but I need it to apply the style change without messing with font size. I use this script to emphasize the price of a product in a promo. The idea is to keep the currency symbol smaller than the numbers while still applying the effect to all the characters, including the “$” symbol. I think I read somewhere trying to affect a range of characters in a text layer is not possible with Extendscript. Is this true? Would it be better having the “$” symbol in a separate layer? I still could use a variation that leaves de “$” untouched for the whole thing while on the same text layer. If someone can direct me on how to isolate the first space in the index for such an effect. Thanks!!

    {app.beginUndoGroup("Jump Text");
    var jumpText = app.project.activeItem.selectedLayers[0];
    var fonts = ["DINNextLTPro-Regular","DINNextLTPro-Italic","DINNextLTPro-Bold"];
    var jumpTextProp = jumpText.property("Source Text");
    var jumpTextDocument = jumpTextProp.value;

    var t = jumpText.inPoint;
    var idx = 0; while (t < jumpText.outPoint){
    jumpTextDocument.font = fonts[idx];
    jumpTextProp.setValueAtTime(t,jumpTextDocument);
    t += .25; idx = (idx+1)%fonts.length;
    }
    app.endUndoGroup();

    }

    Sergio Pol replied 11 years ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    August 8, 2015 at 7:01 am

    I think a separate text layer for the “$” is pretty much your only option.

    Dan

  • Sergio Pol

    August 8, 2015 at 4:22 pm

    Ok, I thought so. What I’m trying to do now is applythis effect to two layers at.once. I created variables for both layers selected and their sunsequent source text variables for each one. Then I didn’t know how to modify the If statement to manage both sets of data at once so I duplicated the if statement and made it handle the variables for.the second layer but when I ran the script AE froze everytime. Any thoughts on how to work around this?

  • Dan Ebberts

    August 8, 2015 at 4:39 pm

    I haven’t tested this, but I’d set it up like this:

    app.beginUndoGroup("Jump Text");
    var fonts = ["DINNextLTPro-Regular","DINNextLTPro-Italic","DINNextLTPro-Bold"];
    var myLayers = app.project.activeItem.selectedLayers[0];
    var jumpText,jumpTextProp,jumpTextDocument,t,idx;
    for (var i = 0; i < myLayers.length; i++){
    jumpText = myLayers[i];
    jumpTextProp = jumpText.property("Source Text");
    jumpTextDocument = jumpTextProp.value;
    t = jumpText.inPoint;
    idx = 0;
    while (t < jumpText.outPoint){
    jumpTextDocument.font = fonts[idx];
    jumpTextProp.setValueAtTime(t,jumpTextDocument);
    t += .25;
    idx = (idx+1)%fonts.length;
    }
    }
    app.endUndoGroup();

    Dan

  • Sergio Pol

    August 8, 2015 at 8:55 pm

    It works Dan, thank you. However, when generating the keyframes it assumes the kerning of the first character in the string and applies to the rest. So when I edit the text to something like 1.990 it gives all characters the kerning of the “1”. This is awful since I’d need to adjust the kerning differently for different cyphers so they look good. But as before I think respecting the given kerning to a text string is not possible for a script right?

  • Dan Ebberts

    August 8, 2015 at 9:23 pm

    As far as I know, that’s correct.

    Dan

  • Sergio Pol

    August 8, 2015 at 9:25 pm

    Ok Dan thanks again.

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