#include statement in JScript


JScript doesn’t include anything like the #include statement, or like modules in Python.

But what you can do is read the contents of a file into a string, and then eval() the string. For example:

var fso = ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile( "//server/scripts/toinclude.js", ForReading );
var s = f.ReadAll();
eval(s);
s.Close();

Note that if there’s any errors in the included code, you won’t get the right line numbers in the error messages.

In JScript, another approach would be to create a custom object that has all the helper functions as methods. For an example of that kind of thing, check out the WizardHelperObj object in

%XSI_HOME%\Addons\sdkui\Application\Plugins\SDKWizards.js

Then you just provide one custom command that returns an instance of the custom object to whatever code needs to use the helper functions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s