Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Data driven expression

New Here ,
Nov 20, 2017 Nov 20, 2017

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!

1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2017 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 20, 2017 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 20, 2017 Nov 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 20, 2017 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2017 Nov 20, 2017

If you have 12 presenters and one template you'll need to create 12 different data files and move each one of them into the Project Panel for AE to find and use the data. If you want to use an external data file then you can point to the path for the data file but you'll have to edit the script or expression loaded in AE to pick a specific data set.

From what I know of your project I would load up the master template in a new AEP, use the name expression I provided, Duplicate and rename the file you wanted to render so it matches a presenter and then add the comp to the render cue or the AME. That would probably be faster than editing a dataset.

I guess I'm still not getting the structure of your comp. If all 12 presenters are in the comp as separate layers and you only want to see one of them then changing the name of the comp would do it quickly.

If you want to replace the presenter layer in a comp then some kind of naming convention and a script is necessary.

If the data-driven infographic layers in your comp change with each presenter then having a JSON file that looks for a presenter layer and matches up the appropriate date is where you want to go. You could just draw all of the resources you need from the Project Panel.

An uncropped screenshot with the modified properties of the layers you are having problems with would be a big help in understanding the production problem. If it were my project and all I wanted to do was customize the presenter I would probably create an image sequence 12 frames long and apply an expression to the image sequence that would freeze frame one of the frames based on the comp name or even the layer name. Even simpler would be just to use a number so the expression would just read the number of the frame you want and freeze there. The expression would not foul up any transitions you wanted to apply to the layer. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 21, 2017 Nov 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:

Screen Shot 2017-11-21 at 09.52.35.png

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 21, 2017 Nov 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 21, 2017 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Dec 14, 2017 Dec 14, 2017

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

Thanks,
Kevin

Kevin Monahan - Sr. Community & Engagement Strategist – Pro Video and Audio
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2018 Feb 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2018 Feb 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2018 Feb 02, 2018

You can build comps that are driven by scripts that read external data files to that all you have to do is launch AE, load the project and run the script. If you want to make changes in the projects you need to rewrite the data that the scripts and point to the new files.

You can create Extended Graphics projects in AE that will open in Premiere Pro and allow you to manually make changes there.

You can create data-driven comps in AE that use JSON scripting but they take a lot of work and you have to enter that data in with a JSON editor when you want to make changes or point to new data files in the AE project. It makes some things easier but still requires you to do some manual work.

There is no solution that I know of that would drop a data file in a folder and have AE read that data file, create a comp, send it to render and then move on to the next project without some human intervention that requires specific skills. IOW, you can't tell the intern that has never seen AE to and go do it and expect it to work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 17, 2020 Feb 17, 2020

sorry for the delay. Actually there is a script for what you describe. It's called Reshoots, and it manages to automate the AE workflow completely. Even automatic production via a json file placed in an ftp folder. The script listens for new remote requests, retrieves the remote footage (if necessary), opens your AE project, personalizes your comp, launches the new render in AME and finally uploads your video. All this in a data-driven session, continuously, until you stop the session from the control panel of the Reshoots script. It also allows personalized delivery, in this case an ftp folder as a destination would be fine. You don't have to get your hands on it. Just let After Effects wait for new requests and produce independently to generate real-time renders. You can download it on www.reshoots.com, I hope it can still be useful for anyone looking for answers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2025 Jul 28, 2025
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines