Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Weird expression behavior, please help.

  • Weird expression behavior, please help.

    Posted by Anthony Honciano on November 30, 2021 at 8:31 pm

    Hello, y’all!

    So I’m dabbing into expressions, and I’ve played with JS before, but I’m no expert and I don’t know how to identify this weirdness and can use some fresh new eyes.

    So I have this expression in a shape layer for the Size, Rotation and Stroke, and a Null with expression control sliders.

    I designed the expression that if I duplicate the shape layer, it will read:
    1. Read the layer name and store it in a value

    2. See’s the layer below it and increase the scale and rotation so I get this cool shape pattern effect.

    3. The scale/rotation values and offsets are controlled by the null.

    Everything (sorta) works as intended (check the GIF), but when it gets to layer 10, it kinda just resets to the scale and rotation values to the first layer. I can’t seem to figure it out. What did I do wrong? To replicate it, simply delete all the Octagon shape layers, but leave Octagon 1. Now duplicate it, and you’ll the new shapes created, but the 10th shape will just reset to the initial value.

    I’ve attached the AE file and you’ll see that the scale and rotation value of “Octagon 10” is the same as “Octagon 1” and just repeats at that point instead of just building off the shapes.

    I’ll copy the script of the shape layer’s scale property. Thank you in advance!

    //get layer name
    layerVal = thisLayer.name;
    //get the number from the layer
    layerVal = layerVal.replace(/[^1-9]/g, '')
    //get just the text
    layerTxtVal = layerVal.replace(/[^a-z]/g, '')
    //convert the string number into an integer
    layerNumVal = parseInt(layerVal);
    xScale = 10; //just place holders
    yScale = 10; //just place holders
    //check if layer is labeled as "1", if so, don't try looking for layer 0(zero)
    if(layerNumVal > 1){
    //Layer is grater than 1, do something

    //get the layer one level down

    layerNumVal = layerNumVal - 1;
    xScale = thisComp.layer("Octagon "+layerNumVal).transform.scale[0]+thisComp.layer("Octagon Null").effect("Scale Offset")("Slider")

    yScale = xScale;

    } else {
    //Layer is #1 Look at null value controls
    xScale = thisComp.layer("Octagon Null").effect("Scale")("Slider")
    yScale = xScale;
    }
    [xScale,yScale]
    Anthony Honciano replied 4 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    November 30, 2021 at 9:00 pm

    It seems like this line:

    layerVal = layerVal.replace(/[^1-9]/g, '')

    will give layerVal a value of 1 for layer “Octagon 10”

  • Anthony Honciano

    November 30, 2021 at 11:19 pm

    Oh that’s weird…so how do I get it to output 10?

  • Anthony Honciano

    November 30, 2021 at 11:23 pm

    OOOH wait, nevermind, it was my mistake. I didn’t specify 0, I had it start start at 1 in the replace function. ALL GOOD! THANKS!

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