Forum Replies Created

Page 25 of 65
  • You could put a marker on the camera layer at the point that you want it to stop and use this expression


    var CamSpeed = thisComp.layer("Adjustment Layer 1").effect("Cam_Speed")("Slider");

    var PULL = time < marker.key(1).time ? value[2] - time * CamSpeed : value[2] - marker.key(1).time * CamSpeed;
    [(value[0], value[1], PULL)];

    Andrei
    My Envato portfolio.

  • You can try this. You can write as many ifs as you want to set the part number you want your text split into.


    function breakTextInEqualParts(myString, partNo) {
    var splits = [0];
    var subStrings = [];
    var strLength = myString.length;
    if (
    partNo < 2 ||
    myString == "" ||
    text.sourceText.indexOf("\n") != -1 ||
    text.sourceText.indexOf("\r") != -1 ||
    text.sourceText.length < 20
    )
    return myString;

    for (var i = 1; i < partNo; i++) {
    splits.push(Math.round(strLength / partNo) + splits[i - 1]);
    }
    splits.push(strLength);

    for (var i = 0; i < strLength - 1; i++) {
    subStrings.push(breakText(myString, splits[i], splits[i + 1]));
    }

    return subStrings.join("\n");

    function breakText(myString, idx1, idx2) {
    if (myString == "") return "";
    idx1 = calcIndex(myString, idx1);
    idx2 = calcIndex(myString, idx2);
    return myString.substring(idx1, idx2);

    function calcIndex(myString, idx) {
    if (idx == 0) return idx;
    var before = myString.lastIndexOf(" ", idx);
    var after = myString.indexOf(" ", idx + 1);

    if (before == -1 || (after != -1 && idx - before >= after - idx)) {
    idx = after;
    } else {
    idx = before;
    }
    return idx;
    }
    }
    }

    var len = text.sourceText.length;
    if (len > 40) parts = 2;
    else if (len > 20) parts = 3;
    else parts = 1;

    var ctrlStyle = thisComp.layer(index - 1).text.sourceText.style;
    val = breakTextInEqualParts(text.sourceText, parts);
    style.setFont(ctrlStyle.font).setText(val).setFontSize(ctrlStyle.fontSize);

    Andrei
    My Envato portfolio.

  • Andrei Popa

    August 6, 2020 at 5:45 am in reply to: 2D Parallax

    I added a slider to the layer, named Factor. This is added to make the control of the speed easier. I also divided it by 100 in my expression to make the customization easier.
    The reference position is the “Control Null” layer’s position.
    You may need to tweak here and there but I think this is a good place to start.


    startP = [thisComp.width/2,thisComp.height/2];
    ctrlP = thisComp.layer("Control Null").position;
    factor = effect("Factor")("Slider")/100;
    value+(ctrlP-startP)*factor

    Andrei
    My Envato portfolio.

  • Andrei Popa

    August 1, 2020 at 11:28 am in reply to: Break a line of text in half to the nearest word

    I tested it like this. I made 2 text layers for text. I added this slightly modified version for the second one. It works as intended. But it does not change fontsize, color or any other properties. Yet.


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "n" + myString.substring(mid + 1);
    }

    if (text.sourceText.indexOf("n") != -1 || text.sourceText.indexOf("r") != -1 || text.sourceText.length<20) {
    style.setFont(thisComp.layer(1).text.sourceText.style.font);
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(thisComp.layer(1).text.sourceText.style.font).setText(val);
    }

    But if you also want to modify font size or other properties, you have to add some stuff to this expression.
    This will be the base expression on which you can add properties.

    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before <= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }
    ctrlStyle = comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style;
    if (text.sourceText.indexOf("\n") != -1 || text.sourceText.indexOf("\r") != -1 || text.sourceText.length<20) {
    style.setFont(ctrlStyle.font);
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(ctrlStyle.font).setText(val);
    }

    You can add properties by adding the following options at the end of the “style.setFont(ctrlStyle.font)” or the “style.setFont(ctrlStyle.font).setText(val)” parts.


    // Set the font used to Arial
    style.setFont(ctrlStyle.font)

    // Set the font size to 80
    style.setFontSize(ctrlStyle.fontSize);

    // Enable Faux Bold with a Boolean
    style.setFauxBold(ctrlStyle.fauxBold)

    // Enable Faux Italics with a Boolean
    style.setFauxItalics(ctrlStyle.fauxItalics)

    // Enable All Caps with a Boolean
    style.setAllCaps(ctrlStyle.allCaps)

    // Enable Small Caps with a Boolean
    style.setSmallCaps(ctrlStyle.smallCaps)

    // Set the Tracking as a number
    style.setTracking(ctrlStyle.tracking);

    // Set the Leading as a number
    style.setLeading(ctrlStyle.leading);

    // Enable Auto Leading with a Boolean
    style.setAutoLeading(ctrlStyle.autoLeading);

    // Set the Baseline Shift as a number
    style.setBaselineShift(ctrlStyle.baselineShift);

    // Set the Stroke Width as a number
    style.setStrokeWidth(ctrlStyle.strokeColor);

    The list is taken from this adress https://helpx.adobe.com/after-effects/using/expressions-text-properties.html

    So, as an example, if you also want to take the size and fill color from the original layer, the final expression will look this way


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }
    ctrlStyle = comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style;
    if (text.sourceText.indexOf("\n") != -1 || text.sourceText.indexOf("\r") != -1 || text.sourceText.length<20) {
    style.setFont(ctrlStyle.font).setFontSize(ctrlStyle.fontSize).setFillColor(ctrlStyle.fillColor);
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(ctrlStyle.font).setText(val).setFontSize(ctrlStyle.fontSize).setFillColor(ctrlStyle.fillColor);
    }

    I hope this was your problem.

    Andrei
    My Envato portfolio.

  • Andrei Popa

    August 1, 2020 at 7:39 am in reply to: Break a line of text in half to the nearest word

    You mean when there are line breaks in the text?
    This is what it was built like. I told you you could replace the “value” with another piece of expression.

    So if this is the case, this should work.


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }

    if (text.sourceText.indexOf("\n") != -1 || text.sourceText.indexOf("\r") != -1 || text.sourceText.length<20) {
    style.setFont(comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style.font);
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style.font).setText(val);
    }

    Andrei
    My Envato portfolio.

  • Andrei Popa

    July 31, 2020 at 1:19 pm in reply to: Break a line of text in half to the nearest word

    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(” “, mid);
    var after = myString.indexOf(” “, mid + 1);

    if (before == -1 || (after != -1 && mid – before >= after – mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + “\n” + myString.substring(mid + 1);
    }

    if (text.sourceText.indexOf(“\n”) != -1 || text.sourceText.indexOf(“\r”) != -1 || text.sourceText.length<20) {
    value;
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(comp(“00 Color Control”).layer(“Headline Text Font Style”).text.sourceText.style.font).setText(val);
    }

    Andrei
    My Envato portfolio.

  • Andrei Popa

    July 31, 2020 at 12:31 pm in reply to: Break a line of text in half to the nearest word

    I was joking, don’t worry, i’m here to help! ?

    I made a mistake in the lase expression. Try this one. Again, you can replace “value” with some other expression if you need to.


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }

    if (text.sourceText.indexOf("\n") != -1 || text.sourceText.indexOf("\r") != -1) {
    value;
    } else {
    val = breakInTwo(text.sourceText);
    style.setFont(comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style.font).setText(val);
    }

    Andrei
    My Envato portfolio.

  • Andrei Popa

    July 31, 2020 at 11:25 am in reply to: Break a line of text in half to the nearest word

    This were easier if you knew what you wanted from the start :))

    You can replace the last “value” with any other piece of expression you want. I say this because maybe you want to use the one with the font.


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }
    val = breakInTwo(text.sourceText);

    if (text.sourceText.indexOf("\n") == -1 || text.sourceText.indexOf("\r") == -1) {
    style.setFont(comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style.font).setText(val);
    } else {
    value;
    }

    Andrei
    My Envato portfolio.

  • Andrei Popa

    July 31, 2020 at 11:06 am in reply to: Break a line of text in half to the nearest word


    function breakInTwo(myString) {
    myString = myString.replace(/\r?\n|\r/g, "");
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0, mid) + "\n" + myString.substring(mid + 1);
    }
    val = breakInTwo(text.sourceText);

    style.setFont(comp("00 Color Control").layer("Headline Text Font Style").text.sourceText.style.font).setText(val);

    Andrei
    My Envato portfolio.

  • Andrei Popa

    July 31, 2020 at 7:29 am in reply to: Break a line of text in half to the nearest word

    Try this


    function breakInTwo(myString) {
    var mid = Math.floor(myString.length / 2);
    var before = myString.lastIndexOf(" ", mid);
    var after = myString.indexOf(" ", mid + 1);

    if (before == -1 || (after != -1 && mid - before >= after - mid)) {
    mid = after;
    } else {
    mid = before;
    }
    return myString.substring(0,mid)+"\n"+myString.substring(mid+1)
    }
    breakInTwo(text.sourceText)

    Andrei
    My Envato portfolio.

Page 25 of 65

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