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

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

Contributor ,
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
Scripting , SDK , Tools

Views

738

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

Votes

Translate

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

Votes

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

Votes

Translate

Translate
Adobe
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

Votes

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
Contributor ,
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!

Votes

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 @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

Votes

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

Copy link to clipboard

Copied

Thank you let me give it a try!

Votes

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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