Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding a [x, y, z] value to an [x, y] value

  • Adding a [x, y, z] value to an [x, y] value

    Posted by Jay Brown on May 27, 2016 at 9:14 pm

    Is there an easy way to add an [x, y, z] value to an [x, y] value?

    You get the error “result must be of dimension 2, not 3”. Is there a way to check the length of the property so that only the [x] and [y]s are added together and the [z] is ignored?

    I can’t seem to figure out an easy way to do this.

    Thanks,
    -Jay

    Jay Brown replied 9 years, 11 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 27, 2016 at 9:55 pm

    Something like this:

    a = [100,100];
    b = [100,100,100];
    a + [b[0],b[1]]

    Dan

  • Jay Brown

    May 27, 2016 at 10:33 pm

    Thanks for the response Dan!

    Sorry I should have fully explained what I’m trying to do. I have a 3D Point controller on a Null and I’m trying to create an expression that works universally for whatever property I add it too. For example the 3D Point values are [25, 50, 100].
    If I add it to rotation the value would be [25]. If I add to the scale it the value would be [25, 50]. If I add it too a 3D point the value would be [25, 50, 100] and so on.

    This is what I started with:

    oSet = thisComp.layer("Controller").effect("Offset")("3D Point");
    value + oSet;

    Is there a way to tell the property to ignore the extra value?

  • Dan Ebberts

    May 27, 2016 at 10:55 pm

    I think this works:


    oSet = thisComp.layer("Controller").effect("Offset")("3D Point");
    if (value instanceof Array){
    if (value.length == 2){
    value + [oSet[0],oSet[1]];
    }else{
    value + oSet;
    }
    }else{
    value + oSet[0];
    }

    Dan

  • Jay Brown

    May 27, 2016 at 11:02 pm

    It works like a charm! You are an absolute legend!

    Originally I tried .length and length() on oSet and kept getting errors, I didn’t even think about trying it on the value itself. I finally get now too how the (value instanceof Array) works!

    thank you so much,
    -Jay

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