Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Checkbox to select X value or Y Value of a Layer

  • Checkbox to select X value or Y Value of a Layer

    Posted by Kevin Snyder on March 3, 2016 at 5:54 pm

    I don’t know if this is possible, but here is a line in my expression that is giving me trouble.

    x=effect(“(S) Layer Control”)(“Layer”).(effect(“Checkbox Control”)(“Checkbox”)==1) .transform.yPosition else .transform.xPosition);

    I am using layer control to select a layer and I want to use a checkbox to determine whether or not it uses data from the position X value or Y value. Any help to get me going in the right direction would be great. Thanks.

    Kevin

    David Conklin replied 10 years, 2 months ago 2 Members · 3 Replies
  • 3 Replies
  • David Conklin

    March 3, 2016 at 6:11 pm

    Something like this should work.

    Change the 2 variables at the top to point to your Layer and Checkbox controls. This expression will output the X-Value of the Layer Control Layer if the box is un-ticked, and the Y-Value if it is ticked.

    var lyrControl = thisLayer("Effects")("Layer Control")("Layer");
    var chkbxControl = thisLayer("Effects")("Checkbox Control")("Checkbox");

    if(!chkbxControl.value){
    lyrControl.position[0]; // use X-position.
    } else {
    lyrControl.position[1]; // use Y-Position
    }

    David Conklin
    Motion Designer

  • Kevin Snyder

    March 3, 2016 at 6:39 pm

    Thanks David for the input. I appreciate it.

    I’m getting an error stating an illegal use of a reserved word. Here is the full expression that I have. I have it working without the check box, but I would love to get it working with the check box to select the x or y value. The overall goal is to select a parent and then map the x or y value to the scale of my “child” layer using sliders to define the range of the parent and the range of the scale for the child… I think I might be in over my head on this one…

    x = var lyrControl = thisLayer("Effects")("Parent Select")("Layer");
    var chkbxControl = thisLayer("Effects")("Map")("Checkbox");

    if(!chkbxControl.value)

    {lyrControl.position[0]; // use X-position.}

    else

    {lyrControl.position[1]; // use Y-Position}

    scaleobject=linear(x,effect("Parent Input 02")("Slider"),effect("Parent Input 01")("Slider"),effect("Child Output 02")("Slider"), effect("Child Output 01")("Slider"));
    [scaleobject,effect("Fixed Scale")("Slider")]

  • David Conklin

    March 3, 2016 at 7:54 pm

    Hey.

    In re-purposing my code, I think some typing/syntax errors may have occurred. For instance on line 1, you have ‘x = var lyrControl = thisLayer’. I think you need to retype this as ‘var lyrControl = thisLayer’ or ‘var x = thisLayer’.

    Syntax errors also exist on lines 6 and 10, where the ‘//’ (signifying a comment) have caused the closing curly brace to not be computed.

    I’ve re-typed the code below. I can’t check it because I don’t have your project setup; however, it is evaluating without syntax errors.

    Good luck!

    var x = thisLayer("Effects")("Parent Select")("Layer");
    var chkbxControl = thisLayer("Effects")("Map")("Checkbox");

    if(!chkbxControl.value){
    x.position[0]; // use X-position.
    }
    else{
    x.position[1]; // use Y-Position
    }

    scaleobject=linear( x, effect("Parent Input 02")("Slider"), effect("Parent Input 01")("Slider"), effect("Child Output 02")("Slider"), effect("Child Output 01")("Slider"));
    [scaleobject,effect("Fixed Scale")("Slider")]

    David Conklin
    Motion Designer

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