Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Code not working anymore

  • Code not working anymore

  • Aaron Asch

    January 18, 2021 at 6:34 pm

    Hello Cow Community. It’s been a while. I haven’t been on here many years. I’m glad to
    see that it’s still thriving. So please forgive me if my question has been asked before.

    I’m having an issue with an old piece of code that is no longer working. Years ago Dan Ebberts wrote a brilliant tutorial “Building the World’s Greatest Cameraman”. I’m sure most are familiar with it, but if not, basically it showed how to control the camera’s point of interest, focus distance, and zoom, using expressions pointing to a null object with a slider control key framed to the index of the layer you want to focus on. He later helped me tweak it to effect the position of the camera as well. The code was pure genius. I loved working with the camera that way. The ability to fly from one layer to the next that easily and seamlessly was awesome. Well, long story short, the expressions no longer work when applied in my current project. I’m getting a ReferenceError: at line 2 of both the Point of Interest and Position expressions. “ReferenceError: this_comp is not defined”. I suspect it may have something to do with how code is written now versus then. Or maybe I simply haven’t set the project up properly. I don’t know. I’m a complete dummy when it comes to expressions. The code is similar and quite long for both expressions so below is just the first part of the point interest expression. The error is at line 2. But as you can see “this_comp”is all over the place. What am I missing? Any help would be much appreciated. Thank you.

    pan_time = .5;
    s = this_comp.layer(“POI Null”).effect(“Slider Control”).param(“Slider”);
    n = s.num_keys;
    if (n==0){ //check for no keyframes
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    new_value = old_value;
    percent = 1.0;
    }
    else if (n==1){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    L = this_comp.layer(s.key(1).value);
    new_value = L.to_world(L.anchor_point);
    percent = 0;
    if (time > s.key(1).time+pan_time){
    percent=1.0;
    }
    else{
    percent = (time – s.key(1).time)/pan_time;
    }
    }

  • Dan Ebberts

    January 18, 2021 at 7:43 pm

    Wow, that is some old code. I haven’t tested this, but I’ve gone through and updated the obsolete keyword syntax. Try it this way (or you could try just changing File > Project Settings > Expressions to Legacy ExtendScript) :

    pan_time = .5;

    s = thisComp.layer("POI Null").effect("Slider Control").param("Slider");

    n = s.num_keys;

    if (n==0){ //check for no keyframes

    L = thisComp.layer(s.valueAtTime(0));

    old_value = L.toWorld(L.anchorPoint);

    new_value = old_value;

    percent = 1.0;

    }else if (n==1){

    L = thisComp.layer(s.valueAtTime(0));

    old_value = L.toWorld(L.anchorPoint);

    L = thisComp.layer(s.key(1).value);

    new_value = L.toWorld(L.anchorPoint);

    percent = 0;

    if (time > s.key(1).time+pan_time){

    percent=1.0;

    }else{

    percent = (time – s.key(1).time)/pan_time;

    }

    }

  • Aaron Asch

    January 18, 2021 at 10:12 pm

    Hi Dan, thanks for the quick response. Indeed that is some old code!! But brilliant none-the-less. As I figured, it was simply out dated. I’ve used it to great effect in the past and now need it again for a current project. It’s always so frustrating when things that used to work no longer do.

    I tried plugging your new code in by itself, and also at the beginning of the original code. As I wasn’t sure how to place it. Both seemed to do the same thing. Everything shifted to the left. So that didn’t quite work.

    Changing the project settings, however, did work for the old code. At least it appears to. I still get an error though. But now it’s a different one. This time at line 29 for both the POI and Position. It says “property or method named ‘time’ in Class ‘Property’ is missing or does not exist.” It’s weird because it says the expression has been disabled but I can still preview it. I’ll keep playing around with it to see if it gives me any other problems. Below are the original codes for the Position and POI. If there is a way to update these to achieve the same result with modern code that would be great!! If it’s too big of an ask, no worries. I can always keyframe!! Thanks again for all of your help.

    Point of interest———————————————————————

    pan_time = .5;
    s = this_comp.layer(“POI Null”).effect(“Slider Control”).param(“Slider”);
    n = s.num_keys;
    if (n==0){ //check for no keyframes
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    new_value = old_value;
    percent = 1.0;
    }
    else if (n==1){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    L = this_comp.layer(s.key(1).value);
    new_value = L.to_world(L.anchor_point);
    percent = 0;
    if (time > s.key(1).time+pan_time){
    percent=1.0;
    }
    else{
    percent = (time – s.key(1).time)/pan_time;
    }
    }
    else if(time > s.key(n).time){
    L = this_comp.layer(s.key(n-1).value);
    old_value = L.to_world(L.anchor_point);
    L = this_comp.layer(s.key(n).value);
    new_value = L.to_world(L.anchor_point);
    percent = 1.0;
    if (time < s.time+pan_time){
    percent= (time-s.key(n).time)/pan_time;
    }
    }
    else if(time < s.key(1).time){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_WORLD(L.anchor_point);
    new_value = old_value;
    percent = 1.0;
    }
    else{
    j = n;
    while(time<s.key(j).time){
    j -= 1;
    }
    if(j==1){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    }
    else{
    L = this_comp.layer(s.key(j-1).value);
    old_value = L.to_world(L.anchor_point);
    }
    L = this_comp.layer(s.key(j).value);
    new_value = L.to_world(L.anchor_point);
    percent = 1.0;
    if (time < s.key(j).time+pan_time){
    percent = (time-s.key(j).time)/pan_time;
    }
    }
    ease(percent,old_value,new_value)
    ______________________________________

    Position—————————————————————————————–

    pan_time = .5;
    s = this_comp.layer(“Main Cam Null”).effect(“Slider Control”).param(“Slider”);
    n = s.num_keys;
    if (n==0){ //check for no keyframes
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    new_value = old_value;
    percent = 1.0;
    }
    else if (n==1){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    L = this_comp.layer(s.key(1).value);
    new_value = L.to_world(L.anchor_point);
    percent = 0;
    if (time > s.key(1).time+pan_time){
    percent=1.0;
    }
    else{
    percent = (time – s.key(1).time)/pan_time;
    }
    }
    else if(time > s.key(n).time){
    L = this_comp.layer(s.key(n-1).value);
    old_value = L.to_world(L.anchor_point);
    L = this_comp.layer(s.key(n).value);
    new_value = L.to_world(L.anchor_point);
    percent = 1.0;
    if (time < s.time+pan_time){
    percent= (time-s.key(n).time)/pan_time;
    }
    }
    else if(time < s.key(1).time){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_WORLD(L.anchor_point);
    new_value = old_value;
    percent = 1.0;
    }
    else{
    j = n;
    while(time<s.key(j).time){
    j -= 1;
    }
    if(j==1){
    L = this_comp.layer(s.value_at_time(0));
    old_value = L.to_world(L.anchor_point);
    }
    else{
    L = this_comp.layer(s.key(j-1).value);
    old_value = L.to_world(L.anchor_point);
    }
    L = this_comp.layer(s.key(j).value);
    new_value = L.to_world(L.anchor_point);
    percent = 1.0;
    if (time < s.key(j).time+pan_time){
    percent = (time-s.key(j).time)/pan_time;
    }
    }
    ease(percent,old_value,new_value)

  • Dan Ebberts

    January 19, 2021 at 12:28 am

    Yeah, that line doesn’t makes sense. Because s is a slider, it wouldn’t have a time property. Maybe it was supposed to be s.key(n).time, or something like that. I found the original project (I think), and I was going to check the original code, but I don’t have a version of AE that’s old enough to open it.

  • Aaron Asch

    January 19, 2021 at 1:44 am

    Dan you are the man. That little change fixed the error. The code is now error free!! I set up a quick test and it seems to be working just fine using the Legacy ExtendScript. So thank you immensely for that!! And yes, I had to dig out an old machine that happened to have 6.5 on it to open the projects as well.

    Thanks once again for all of your help both in the past and now. You have been an indispensable asset to this community for a very long time. I genuinely appreciate what you do.

  • Othman Ahmed

    January 19, 2021 at 9:32 am

    Hello Dan, Hope you doing great!

    Please, Where can I find the original “Building the World’s Greatest Cameraman” thread?

Viewing 1 - 6 of 6 posts

Log in to reply.

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