Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Combining Slider value with text variable, is this possible?

  • Combining Slider value with text variable, is this possible?

    Posted by Billy Sides on March 6, 2013 at 7:52 pm

    I have a slider that I want to drive a file name ie.
    myComp_+SLIDER VALUE+_link

    end result would be something like this:
    myComp_1_link
    myComp_2_link
    myComp_3_link

    I keep getting this error:
    Invalid Numeric Result (divide by zero?)

    I think it’s due to the fact I’m trying to combine a number with a text string.

    Any ideas how to combine the two?

    Thanks,

    -bsides

    Thomas Frenkel replied 9 years, 4 months ago 5 Members · 10 Replies
  • 10 Replies
  • Dan Ebberts

    March 6, 2013 at 9:38 pm

    Probably more like this:

    myComp.name + “_” + Math.round(mySliderVal) + “_link”;

    Dan

  • Billy Sides

    March 6, 2013 at 10:23 pm

    Thanks Dan, that worked just fine. Weird that you have to round the number to add it to a string…

    Thanks again,

    -bsides

  • Dan Ebberts

    March 6, 2013 at 10:34 pm

    You don’t have to round it, but you don’t want to end up with 0.99999999999997 instead of 1. I’d do it just to make sure you end up with an integer.

    Dan

  • Jeff Bobbington

    May 13, 2014 at 2:10 pm

    Is it possible to have a text layer read out a number from a slider without rounding it up?
    My text layer has a slider(Time), the source text expression is this:

    t = effect("Time")("Slider");

    'Timer: '+t

    In my mind, this should simply make the text read ‘Timer: 53.46’, but instead it tells me that it’s an invalid numerical result. Annoyingly, it works fine if I apply Math.round to the time expression.

  • Dan Ebberts

    May 13, 2014 at 2:13 pm

    Try it this way:

    t = effect(“Time”)(“Slider”).value;
    ‘Timer: ‘+t

    Dan

  • Jeff Bobbington

    May 13, 2014 at 2:54 pm

    That worked, I already tried it actaully, but I guess my text box was cutting off the value so I assumed it didn’t. Derp!

    Thanks Sir

  • Gabriel Ferrão

    September 11, 2014 at 6:43 pm

    Hi there,

    Is it possible to change the value within “” with a slider?

    I’ve got a layer that has three effects (Red Giant’s Sound Keys). Inside each of these effects, there are three values that are of interest to me.

    I’d like to write an expression (using sliders), where I can toggle between the three different effects, and within that, toggle between those three different values.

    Here is the string I’m trying to alter:

    thisComp.layer(“SOUNDKEYS”).effect(“Sound Keys 3”)(“Output 1”)

    I was hoping that I could select the number 3, for example, and pick-whip that to a slider, but it didn’t work.
    Then I decided to use what someone suggested earlier and do something like

    S=effect(“SOUNDKEYS #”)(“Slider”);
    thisComp.layer(“SOUNDKEYS”).effect(“Sound Keys S”)(“Output 1”)

    But the result is that “Sound Keys S” is missing or does not exist.

    Hope that makes sense…
    I’m trying to avoid going into the expression and manually changing the numeric values, since I’d have to do that countless times.
    Thanks!

  • Dan Ebberts

    September 11, 2014 at 6:59 pm

    That would be something like this:

    n = Math.round(effect(“Slider Control”)(“Slider”));
    thisComp.layer(“SOUNDKEYS”).effect(“Sound Keys ” + n)(“Output 1”)

    Dan

  • Thomas Frenkel

    December 15, 2016 at 10:05 am

    Sorry for digging out this out thread, but I need some help in a quite similar case:

    I have a slider control with values between 1000 and 300000 that I linked to the sourceText. I want to add a dot to have the numbers display like this:

    1.000,
    300.000,
    etc

    I want to keep the luxury of just animating the slider to change the current value. So my guess was to use “length” to get the total amount of characters and work with “substring” for the part before the dot and the part after the dot:

    val=Math.round(SLIDER); //value like “300000”
    amountChars=val.length; //amount of characters
    sString=amountChars-3; //dot is right before the last 3 chars
    val.substr(0,sString); // the first part of the value before the dot

    The problem is, that substring won’t recognize the slider values as a string (unlike the sourceText parameter);
    It works when I use normal text, but not when I input the slider values.

    Would appreciate some help

  • Thomas Frenkel

    December 15, 2016 at 10:24 am

    Ah, I found a workaround:

    I am working with 2 text layers now:

    One uses the slider for the sourceText, which will convert the slider values to a string. This layer is just for the conversion and is not displayed.

    The second text layer will use the converted sourceText of the first layer by just linking it. Then I did the following expression to get the dot:

    val=thisComp.layer(“INPUT”).text.sourceText;
    amtC=val.length;
    sString=amtC-3;
    sString2=3;
    val.substr(0,sString)+”.”+val.substr(sString,amtC);

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