Skip to main content
Participant
November 20, 2017
Question

Data driven expression

  • November 20, 2017
  • 5 replies
  • 1344 views

Hi, any help much appreciated! I'm a novice when it comes to scripting in AE, and was wondering if someone knew how to write an expression that would either control the opacity of a layer (to make it visible or not) or toggle the visibility of the layer (if that's possible).

I have an AE template with a set of 12 presenter images in it. What I want to do is automate which presenter is made visible.

This would need to be controlled by an external JSON script, so for instance in my JSON script, I have :

[

{

"Reporter": "presenter_john_smith"

}

]

What I want to do, is if "presenter_john_smith" is present in the JSON, then this presenter image shows up at 100% opacity in the comp, all the other presenters will have the same expression, but are looking for a different name in the JSON, so will be opacity 0. This is what i've put in the opacity as an expression, which doesn't work:

myData = footage("presenters.json").sourceData[0];

data = myData.Reporter("presenter_john_smith") = active;100

Does that make sense? Hope someone can help!

    5 replies

    Participating Frequently
    July 28, 2025

    I'm aware I'm late to this party - very much late - but this might be handy for anyone who is looking for a similar solution in the future.

     

    There's a way to achieve this nowadays with Plainly Videos. You would simply send a JSON with the parameters as @geoffsummerfield outlined in his example to the Plainly's API, and it would change the data in the video.

     

    You'd still have to set up expressions in the project that would change the opacity of different layers based on the input but that's pretty simple.

    Kevin J. Monahan Jr.
    Community Manager
    Community Manager
    December 14, 2017

    Did you ever get this sorted out, GeoffSummerfield? Let us know.

    Thanks,
    Kevin

    Kevin Monahan - Sr. Community and Engagement Strategist – Adobe Pro Video and Audio
    Participant
    February 2, 2018

    Hi Kevin, no, I didn't get a solution, as most of the replies go completely over my head, having never done any scripting or use of expressions previously!! Perhaps you could answer if it's possible to auto run a script, or have an expression on a video/footage layer which will control the visibility or opacity of a video layer based on data/text from a JSON file? This cannot be achieved any other way, it HAS to be controlled by data from a JSON, as what i'm looking to achieve is a fully automated AEP project solution, with no manual intervention whatsoever?

    Thanks, Geoff.

    Dave_LaRonde
    Inspiring
    February 2, 2018

    geoffsummerfield  wrote

    ....what i'm looking to achieve is a fully automated AEP project solution, with no manual intervention whatsoever....

    Two words -- dream on.

    That is NOT going to happen.  I fear you'll have to do actual WORK on this.

    Participant
    November 21, 2017

    Hi guys, thanks again for taking the time to help me out! I'm still not sure i'm making myself too clear in what i'm trying to achieve. It's for a client, so I can't be too specific or show exactly what I'm doing for them, but here's an example, which is the same concept but simplified with less data and AE layers:

    I need to create an AE infographic comp which is populated by incoming JSON data. The user/client will have NO After Effects knowledge, and will not be able to do anything to the comp, it needs to be a FULLY automated process, they will simply send the template to a render watch folder.

    For example, I will create a 30 second Weather bulletin. It will have the name of the City (let’s say London), 7 days for temps. and respective weather symbols, a text summary, a background video layer of the city (lets say there are 4 in the comp - London, Edinburgh, Cardiff and Belfast, with only LONDON made visible) and 4 different (targa sequence assets) presenter layers (Hayley, Jane, Steve and Bob - again lets say only JANE made visible).

    My JSON looks like this: (weather.json)

    [

    {

    "City": “LONDON”,

    "Sunday": 8,

    "Monday": 9,

    "Tuesday": 8,

    "Wednesday": 7,

    "Thursday": 7,

    "Friday": 7,

    "Saturday": 6,

    "Facts": "MIXED OUTLOOK FOR THE WEEK AHEAD. VERY UNSETTLED WITH STRONG EASTERLY WINDS.",

    "BG": “LONDON”,

    "Reporter": "JANE",

    }

    ]

    My AEP looks like this:

    My script for the text fields looks like this (for example, the City title):

    myData = footage(“weather.json").sourceData[0];

    data = myData.City

    SO… what i’m looking to achieve is a solution where the 4 respective City video backgrounds, and 4 presenters are made visible or not depending on the infographic data - which city the bulletin is for, and who the presenter is.

    Thanks in advance… Geoff.

    Participant
    November 21, 2017

    The simplist methodology in my head is that the 4 background video laters and 4 presenter PNG sequences are all present in the comp, and each has a script attached to the opacity that says something like -

    IF myData.BG = “LONDON” then opacity = 100, otherwise opacity = 0 (for the LONDON.mp4 layer)

    IF myData.BG = “EDINBURGH” then opacity = 100, otherwise opacity = 0 (for the EDINBURGH.mp4 layer)

    IF myData.BG = “CARDIFF” then opacity = 100, otherwise opacity = 0 (for the CARDIFF.mp4 layer)

    IF myData.BG = “BELFAST” then opacity = 100, otherwise opacity = 0 (for the BELFAST.mp4 layer)

    As I say, I'm a novice to scripting, so this may not be the best solution, but seemed the most logical to me!

    Mylenium
    Legend
    November 21, 2017

    I still think you are completely missing the part  where I said that the data as such has no active logic. Also matching a string is a different thing than matching a value. I don't see any booleans in your code. You would probably have to write some RegEx and then use its return value (true or false) as a trigger or directly match it to the layer name. It also seems to me you are oversimplificating your JSON. Why not establish a proper node/ stream hierarchy and instead of having the cities dumped in the root have a "cities" branch and fetch a name and boolean for the visibility from there? That probably could even be said für your day names, forecast images etc. and so on. As it is, you are really not using the potential.

    Mylenium

    Mylenium
    Legend
    November 20, 2017

    The "active" method only applies to whether an item is actually visible/ exists, not the actual data, so you'd have to create JSON-based keyframes that contain the data. Aside from that, if there are really only 12 presenters, it seems like a lot of trouble for very little effect. You could just have a bunch of checkboxes or an expression slider somewhere to fetch those names from a text layer with some string processing with the added benefit of not having to worry about external references. That or as Rick already suggested simply use some naming-based trickery, which could include creatively using a dummy text layer just as well. You're really overcomplicating this and are trying to do surgery with a chainsaw here...

    Mylenium

    Participant
    November 20, 2017

    Hi guys, thanks for the replies. I guess what complicates matters is that

    the presenter is only one layer in the comp (a set of prerendered 3d targa

    sequences) which is part of a larger data driven promo comp (containing

    about 15 text and infographic data fields, which I have working). As each

    one will be presented by a different reporter, I wanted to create one

    template which can be auto driven if that makes sense? So the presenter is

    only one part of the comp, and their clip is selected as part of the wider

    data population). I just wanted to highlight this bit so as not to

    complicate matters in my request for info! Sorry if I caused confusion!

    Mylenium
    Legend
    November 20, 2017

    Well, you're still going to need some conditional and the names have to be available internallly to provide a reference to check against, so I don't see how using JSON would do anything here. Ultimately that's the whole point: You use the data directly, everything else is still dependent on AE's native means. So unless you can generate it in a way that would equal frames that are directly funneled to the text layer, it doesn't do anything to simplify your template. You still need one of those expression hacks we pointed out. The data itself has no inherent logic.

    Mylenium

    Community Expert
    November 20, 2017

    I would make it incredibly simple by writing an expression that refers to the name of the composition. If the comp name matches the presenter layer name the opacity is 100% otherwise it is zero. Then you just name the composition. Apply this expression to the opacity property.

    n = name;

    c = thisComp.name;

    if (c == n) 100

    else 0

    Another option would be to put the presenter that is active on the top layer by just dragging the layer to the top. No expression needed if all the presenter layers are the same size.

    If you want to drive this externally you'll have to have a separate text file in the Project Panel for each presenter. It seems to me the easiest solution would be to just rename the comp before you send it to render.