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

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

Participant ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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.

TOPICS
How to , Scripting , SDK , Tools

Views

480

Likes

Translate

Translate

Report

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

correct answers 3 Correct answers

Community Expert , Nov 14, 2022 Nov 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

Likes

Translate

Translate
Community Expert , Nov 14, 2022 Nov 14, 2022

Hi @Antonio Pacheco HN ,

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.

Likes

Translate

Translate
Community Expert , Nov 14, 2022 Nov 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

Likes

Translate

Translate
Community Expert ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Participant ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

Hi @Antonio Pacheco HN ,

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

Likes

Translate

Translate

Report

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
Participant ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

Thank you let me give it a try!

Likes

Translate

Translate

Report

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 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Participant ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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