Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Opacity control from data in .json

  • Opacity control from data in .json

    Posted by Gary Sweeney on March 11, 2019 at 11:40 am

    I’m looking for a way to have an image at 100% opacity if the data in the .json says the name of the image so something like this…

    input = footage(“datafile.json”).sourceData[46].NAMES;

    if (input=thisLayer.name){value = 100}
    else {0};

    So the ” [46].NAMES ” part looks for the name of the person in the .json and that works fine.
    (I can get it to say the name in a text layer)

    I just don’t know how to get the opacity of the image to be 100 if it says the name and 0 if it doesn’t.
    I’m sure this is probably basic put any help is greatly appreciated.

    Gary Sweeney replied 7 years, 4 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    March 11, 2019 at 2:11 pm

    I haven’t tested this, but give it a try:

    input = footage(“datafile.json”).sourceData[46].NAMES;
    (input == name) ? 100 : 0

    Dan

  • Scott Mcgee

    March 11, 2019 at 2:11 pm

    Try below if the input is working. Looks like you’re missing an =. should be ==

    input = footage(“datafile.json”).sourceData[46].NAMES;

    if (input == thisLayer.name){value = 100}
    else {0};

  • Gary Sweeney

    March 12, 2019 at 12:26 pm

    Hi Dan,

    Yes that works perfectly, really appreciate the help! I have another question if you have the time.

    I want to position the same image layer in a specific position depending on the data.
    I’ve put the code in below and it’s not having it when I had the ‘else if’ lines in but will work with just the if line & the else line at the end.

    input = footage(“datafile.json”).sourceData[46].CITY;

    if (input == “London”){[625.5,100.75]}
    else if (input == “Dublin”){[625.5,200.75]}
    else if (input == “Glasgow”){[625.5,300.75]}
    else if (input == “Cardiff”){[625.5,400.75]}
    else if (input == “Belfast”){[625.5,500.75]}
    else {[0,0]};

    Thanks
    Gary

    PS – Also what do you recommend is the best way forward in terms of learning all there is to know about this?

    input = footage("datafile.json").sourceData[46].CITY;

    if (input == “London”){[625.5,100.75]}
    else if (input == “Dublin”){[625.5,200.75]}
    else if (input == “Glasgow”){[625.5,300.75]}
    else if (input == “Cardiff”){[625.5,400.75]}
    else if (input == “Belfast”){[625.5,500.75]}
    else {[0,0]};

  • Gary Sweeney

    March 12, 2019 at 12:29 pm

    Thanks Scott, this also works perfectly too.

    If you also have time for the other question I asked Dan above it would be appreciated.

  • Dan Ebberts

    March 12, 2019 at 12:59 pm

    You’re using curly quotes around your city names, use straight quotes instead.

    Dan

  • Gary Sweeney

    March 12, 2019 at 2:00 pm

    Thanks again Dan, I’m an idiot.

    The next issue I have is I’ve ended up with 2 or more images overlapping each other.
    You don’t know of a way the images can be offset if they happen to be in the same location?

  • Dan Ebberts

    March 12, 2019 at 4:56 pm

    It might be a little tricky, and depends a lot on how you have things set up, but rather than have the expression for each image’s position have to keep track of all the other images, you might want to move all that logic to an invisible text layer that, based on the json data, calculates where everybody should be and then publishes a list. Then each image has a position expression that gets its position from the list. Something like that.

    Dan

  • Gary Sweeney

    March 13, 2019 at 10:32 am

    That sounds exactly what I need Dan.


    (The error message is only down to not having the json loaded on this screenshot, it does work)

    My set up is shown in the images above, I have a main project showing a map and then 3 projects overlaying within it.
    In the project folders are the person’s heads which will move to the locations depending on the data.
    So there are times where different people will be in the same location but in different projects.
    The text layer at the top of the project is an invisible text layer that references the row in my json file required.

    What would be the way to put everything in an invisible text layer, calculate where everybody should be and then publish a list?
    I also assume this way would speed up the preview speed as it is very very slow at the minute.

    Gary

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