Is it possible to call a function from another codebox

Andro's icon

Hi everyone,

Quick question.
I have a jit.gl.pix object where I'm doing everything with codebox.
Is it possible to have 2 instances of codebox (in the same jit.gl.pix object) and call a function from one codebox into another.
codebox 1 (main code) - can I call functions from codebox 2 into this one ?
codebox 2 (other functions)

This is to try and keep my code tidy and ordered instead of ending up with one codebox being 4 pages long .

Thanks !

Andro's icon

Alright ,found the part in the reference for "genexpr" which states the following.
----------------Requiring GenExpr Files

When defining operators in GenExpr, it can be handy to keep them in a separate file so that they can be reused frequently without having to constantly re-type the operator definition in a codebox. To include GenExpr operators defined in a separate file, use the require operator. The require operator takes the name of a .genexpr file and loads its definitions. The following are all valid ways to require a .genexpr file:

require("mylib")
require("mylib");
require"mylib"
require"mylib";

In the above code, calling require triggers the codebox to look for the file 'mylib.genexpr' using the Max search paths. Required .genexpr files can also require other files. If a file is required more than once, it will only be loaded once.

GenExpr files can be created and edited using the built-in Max text editor. If a GenExpr file is required in a gen object and the file is edited and saved, the gen object will detect that a file it depends on has changed through filewatching and recompile itself to reflect the new changes.
------------------

So I've saved a file called Shapes_01.genjit in my shared folder (this is in my search paths for max)
I then type into my main codebox (at the very top of the script)
require("Shapes_01");
I then get the following error ;
"unable to find .genexpr include file Shapes_01"

So i can see that my shapes_01 file is genjit and not .genexpr. file.
I just can't seem to find a way to save my jit.gl.pix codebox file as a .genexpr

Any tips on this one ?

Andro's icon

Solved.
I assumed it would be possible to save a .genexpr file from max/jit.gl.pix (maybe it's possible didn't find out how though)
I just pasted my codebox script into textwrangler and saved it as shapes_01.genexpr
require("shapes_01"); // now works inside of my main script

Maybe an idea to add to the documentation that an external text editor has to be used to create a .genexpr file ?

Ernest's icon

thank you )