Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Changing object colour relating to values in json import

  • Changing object colour relating to values in json import

    Posted by Gary Sweeney on July 17, 2018 at 11:40 am

    Hi,

    I’m trying to create a heat map style graphic relating to the image below.

    I want each of the zones to change colour depending on values relating to a json import.

    Ideally the colour would change from green to red depending on the value, with 0 (min) being green and say 40 (max) being red.

    I have very limited knowledge of expressions and would appreciate any help.

    Thanks, Gary

    Scott Mcgee replied 8 years ago 2 Members · 3 Replies
  • 3 Replies
  • Scott Mcgee

    July 17, 2018 at 11:58 am

    I don’t know your layout for your Json, but this is the idea behind it. Also I’ve just copied and pasted the colours I used for a weather map. So you’ll want to look at what colour values you’d want.

    txt = footage(“file.json”).sourceData;
    input = txt.zone1

    if ( input <= 5 && input >= 0 ){
    ([0,255,210,255]/255)}
    else if ( input <= 10 && input >= 6 ){
    ([0,255,190,255]/255)}
    else if ( input <= 15 && input >= 11 ){
    ([0,255,170,255]/255)}
    else if ( input <= 20 && input >= 16 ){
    ([0,255,150,255]/255)}
    else if ( input <= 25 && input >= 21 ){
    ([232,255,0,255]/255)}
    else if ( input <= 30 && input >= 26 ){
    ([252,210,0,255]/255)
    }else{
    ([255,255,255,255]/255)};

    If you are clever about it, you could label your layers and use

    a = thisLayer.name
    txt = footage(“file.json”).sourceData;
    input = txt[a]

    This would allow you to just copy and paste the expression onto all layers and you layer names will trigger that.

  • Gary Sweeney

    July 18, 2018 at 11:25 am

    Hi Scott,

    Thanks for the reply, I think I understand what you are saying, I’m just struggling to figure out how to link my json to the input part.

    I should’ve attached my json file in the last post, here is what I’m working with.
    12559_pitchmap.json.zip
    Zone 1 represents an individual receiving a ball & Zone 2 is where it goes.

    Sorry for the lack of knowledge, just starting to get my head around it.

    Thanks

  • Scott Mcgee

    July 20, 2018 at 8:10 am

    I noticed an issue with your json, which was it flagging issues for me when importing it? But it was the Zone: “One” and Zone: “Two”. It appeared to not like the “”, but after deleting and retyping it let me import it.

    otherwise this worked fine for me. Also I included the part that uses the layers name to reference it so you would only need to reference the array you want [0] or [1], based on your json layer.

    txt = footage(“pitchmap.json”).sourceData;
    a = thisLayer.name;
    input = txt[0][a];

    if ( input <= 5 && input >= 0 ){
    ([0,255,210,255]/255)}
    else if ( input <= 10 && input >= 6 ){
    ([0,255,190,255]/255)}
    else if ( input <= 15 && input >= 11 ){
    ([0,255,170,255]/255)}
    else if ( input <= 20 && input >= 16 ){
    ([0,255,150,255]/255)}
    else if ( input <= 25 && input >= 21 ){
    ([232,255,0,255]/255)}
    else if ( input <= 30 && input >= 26 ){
    ([252,210,0,255]/255)
    }else{
    ([255,255,255,255]/255)};

    Don’t forget when exporting you also need to put it onto the timeline otherwise the export will come out wrong.

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