Skip to main content
SimonBjörk
Known Participant
January 14, 2021
Question

How to "layout" a script with multiple files?

  • January 14, 2021
  • 1 reply
  • 2554 views

I'm writing a script that needs to be split up into multiple parts. I've never done such a thing for After Effects scripts, so I'm a bit sure of the "layout".

 

Lets say I have 4 files, gui.jsx, utils.jsx, render.jsx, import.jsx.

 

- Add gui.jsx to the ScriptsUI folder.

- Create a new folder (../ScriptsUI/extras) and put the other three scripts in that folder.

- render.jsx needs methods from utils.jsx. To make them availible,, add the following at the top of render.jsx

 

$.evalFile(utils.jsx);

 

- gui.jsx needs both utils.jsx and render.jsx. So I guess I add both using the same method as above? Note that that will make utils "import" twice. Is that a problem?

 

Any feedback on this approach?

 

Thanks!

/Simon

This topic has been closed for replies.

1 reply

Tomas Sinkunas
Legend
January 15, 2021

Which one is your main entry point file? Is it gui.jsx? If so, then declare all dependencies in this file. Basically, if you have dependencies in multiple files, it's best to define them in the top-level file, so you do not duplicate insertion. Here's the gist:

// gui.jsx
#include "lib/utils.jsx"
#include "lib/render.jsx"
#include "lib/import.jsx"


// here goes the rest of you gui.jsx file content
SimonBjörk
Known Participant
January 15, 2021

Thanks Tomas!

 

So how do I call functions that are imported from another script/lib? Say that I have a filepath() function in utils.jsx. Do I just call filepath() in the other scripts as well?

 

The downside to this is that it's hard to backtrack which script a function belongs to. For example, if I use the filepath() function in render.jsx, I have no way of knowing which script the source is in?

SimonBjörk
Known Participant
January 15, 2021

Basically, it would be nice if I could call functions from other script like you do in Python, something like utils.filepath().