You can run any script file simply by typing the name of the file (without the .lsf extension). For example, if you create the file create_array.lsf, you can run this file from the command prompt, or another script file, with the command
The current working directory is always in the Lumerical script path, and is the most common location for your script files. You can add additional locations to the path with the addpath script function. The following location (within the installation directory) is also always in the path, making it a convenient place to put script functions that may be needed my all users of the computer. It will be necessary to have admin access to save files in this location.
- C:\Program Files\Lumerical\FDTD\scripts (Windows)
- /usr/local/lumerical/scripts (Linux)
Note: Saving script files with the same name as built in script functions
It is generally not recommended to create script files that have the same name as the standard script functions. In such cases, where there is a conflict between a script file and standard script function, the script file will run. In other words, this allows you to override the behavior of a standard script function. This can be helpful, but it can also lead to confusing behavior when done unintentionally.
Calling one script file from another
Once you start creating complex scripts, it may be convenient to split them up into a number of simpler scripts that call one another. If you have multiple scripts in the same directory then they can call each other just as you would use any other scripting command.
All script files use a common variable space. As a consequence, variables defined in the scripts are global, and the script files have access to all variables defined in the simulation project file. This can lead to problems when two script files use the same variable names. For example, script_1.lsf (defined below) will print the value 10 to the command line since script_2.lsf modified the variable i.
Defining helper function
Calling one script file from another can also help define some simple custom functions. For example, you can define you own function in a custom_function.lsf. Then define the variables in main.lsf and call the helper function.
- Multiple commands are allowed on a single line.
- Blank lines, space and tabs will be ignored. Therefore you can format your script files any way you choose.
- Each command must be terminated with a semicolon.
- On any line, all characters after a # symbol are ignored.
Finally, you can not define a variable or assign values to a variable that has the same name as one of the script commands. For example, the following lines
sum = matrix(1,2);
angle = acos(pi/2);
are not valid statements since 'sum' and 'angle' are script functions.
User defined functions
Alternatively, users have the option to define their own script functions with arbitrary inputs and output without the need to create a separate script file. This can be done through user defined functions.