Skip to main content
Inspiring
November 14, 2022
Answered

how to Include or call other scripts and functions from another file.

  • November 14, 2022
  • 3 replies
  • 1357 views

Hi community good afternoon,

 

just as the title says, does anyone know how to inlclude other scripts and libraries in the same script? For example I have a function named "C" in script "B" and I want to #Include "B" or something like that to call it from another file "A".

 

Thank you in advance.

This topic has been closed for replies.
Correct answer CarlosCanto

just add the #include "full path" directive at top of your script

 

https://community.adobe.com/t5/illustrator-discussions/include-does-not-accept-spaces/m-p/4462966

3 replies

CarlosCanto
CarlosCantoCorrect answer
Braniac
November 14, 2022

just add the #include "full path" directive at top of your script

 

https://community.adobe.com/t5/illustrator-discussions/include-does-not-accept-spaces/m-p/4462966

Inspiring
November 14, 2022

I did not know about this thread, thank you! It's usefull

Charu Rajput
Braniac
November 14, 2022

Hi @AntonioPacheco ,

You can use the #include "fileName" to access the function from another file.

 

Example:

1. Create file B.jsx and paste below code in that file.

 

function C(){
    alert("Hi I am function C() from B.jsx file");
}

 

2. Create another file name as A.jsx and copy paste below.

 

#include "B.jsx";

function main(){
    alert("I am main() function in script A.jsx and will call function C() from B.jsx");
    C();
}

main();

 

Assuming, B.jsx and A.jsx files are in same folder.

Best regards
Inspiring
November 14, 2022

Thank you let me give it a try!

m1b
Braniac
November 14, 2022

Are you using VSCode? The simplest way is to use an "include" directive at the top of your script.

//@include 'path/to/script here.js'

 This will have the effect of "running" the included script before running the script you are editing. Make sure the included script is terminated with a semicolon ;

- Mark

Inspiring
November 14, 2022

Yes I am using VS code! Thank you very much! Let me try this, thanks for all your help!