Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need more efficient code for digital clock automation.

  • Need more efficient code for digital clock automation.

    Posted by Fynn Laue on February 27, 2013 at 12:55 pm

    So I have been working on making a digital clock in shape-layers to be able to have maximum manipulation-possibilities without having to change every single part individually.
    The way it works is:
    – Every digit on the clock has 7 layers (shape objects) for every “stroke”.
    – The shape of every object is linked to the shape of the first stroke in the first digit so all changes to that one, translates to all other strokes.
    – The numbers beneath each digit is a text layer that controls the strokes in every digit:
    – Every stroke has an expression (see below) on the opacity to make it turn on/off according to what number should be displayed.

    So, everything works fine, BUT it is very slow. Even when I don’t play back, my cpu clocks at around 67%.
    I really need more efficient code for this, or just a better way to do it so I hope someone can help me out here.

    My Specs:
    AE CS6 on an iMac mid 2010, OS X Lion, intel i5 2,8 GHz, 16GB 1333MGz RAM, ATI 5750 radeon HD 1GB
    comp setup: clocksetup.png
    below is the code for the opacity expression.

    if (thisComp.layer("Digit 1").text.sourceText==1)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==3)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==4)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==5)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==6)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==7)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==8)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==9)[100]
    else if (thisComp.layer("Digit 1").text.sourceText==0)[100]
    else [0];

    Fynn Laue replied 13 years, 2 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    February 27, 2013 at 7:20 pm

    For one thing, you should only retrieve the value of the text once. Then I would use one conditional statement based on the fewest members of the set. For example, say the middle segment should be on for every digit except 0, 1, and 7. I would set that up like this:

    txt = thisComp.layer(“Digit 1”).text.sourceText;
    if (txt == “0” || txt == “1” || txt == “7”) 0 else 100

    Your example from above would be:

    txt = thisComp.layer(“Digit 1”).text.sourceText;
    if (txt == “2”) 0 else 100

    Dan

  • Fynn Laue

    February 28, 2013 at 1:44 am

    Hey Dan,
    Thanks for taking the time! The code works really well, I love how short and clear it is now.
    However the whole comp still is incredibly slow. My cpu is mostly at around 70%. Sometimes it jumps around all the way from 1%-100%. It is really strange.
    I have googled a bit for problems with expressions, and everyone seems to be very unhappy with how slow they are. Is that just the way it is, or is there a way I can make my comp be faster?
    Please note, that I have a lot of child-layers parented to nulls so I can scale every digit uniformly and unparenting the path of the shape-objects didn’t seem to help much.

    cheers, Fynn.

  • Dan Ebberts

    February 28, 2013 at 4:31 am

    Something in your first post caught my eye:

    >The shape of every object is linked to the shape of the first stroke in the first digit so all changes to that one, translates to all other strokes.

    Is this by expression? As an experiment you could try converting those expressions to keyframes. Then you could delete the keyframes and leave the expressions disabled. See if that helps your performance. If you later need to edit the shape, re-enable the expressions and go through the process again.

    Dan

  • Fynn Laue

    February 28, 2013 at 7:56 pm

    yes, it’s by expression. I started disabling all linked expression shapes (by pressing the “=” in the expression). Didn’t seem to do much.
    Could it be possible that shape-layers just have a high cpu-usage or because I have so many of them?
    Or does After Effects maybe also cache/buffer all other comps in the project, even if they’re not open in a tab?

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