Lumerical script can be executed in the Script Prompt and the Script File Editor. The Script Prompt is generally used for simple snippets of script commands. For a more general use of the commands, the Script File Editor would be more appropriate.
By default, the Script Prompt is located at the bottom of the CAD window. The following are some of its behavior worth noting:
- The commands are executed as soon as the ENTER button is pressed on the command line.
- If a semicolon is missing at the end of a single-line command, it is automatically added.
- When multiple lines are pasted into the script prompt, each line, apart from the last one, should end with a semi-colon.
The Script File Editor contains buttons to create, open, save, and run script files. When multiple script files are open, pressing on the run script button runs the one in the forefront.
When running a script file in a different directory using the GUI, the current working directory is unchanged, but the directory of the script file is added to the scripting path. This way, any files called by that script will be found. However, the search order is
- the current directory
- any other folders in the path
- the directory of the script file
Useful buttons
Below is a list of additional buttons and hotkeys that you might find helpful:
Change working directory
Clicking this button changes the working directory to the directory of the current script file. If the script file has not yet been saved and no directory is associated, clicking on it would not make any difference.
Reload script
This button can be useful if you inadvertently made a change to your script and want to reload the most recent saved version.
Run script (F5)
Clicking this button or the "F5" hotkey runs the whole of the current script file. If you want to run only selected lines of the script, right-click on the selection and select the "Run Selection" option (alternatively, "F9").
Select the current code block
You can use '##' to separate your code into blocks. For the block separator to work properly, there should not be any non-space characters before and after it. When you click this button, it will select the block where the cursor is.
Run current code block and advance
Clicking this button runs the currently selected code block and advances to the next available block. This button is grayed out if there is no code block selected.
Run and debug script
Runs script file in debug mode where execution will break on breakpoints or when stepping.
Hotkeys for formatting and files
- CTRL+] : Indent
CTRL+[ : Unindent
Add or remove four spaces to either the current line or all selected lines. - CTRL+/ : Toggle comment/uncomment
CTRL+R : Comment
CTRL+T : Uncomment
This will add or remove one "#" to the start of either the current line or all selected lines. It does it immediately before the first non-whitespace character in the line. Lines that are all whitespace are ignored. - CTRL+TAB/BACKTAB : Indent/de-indent
- CTRL+I : Smart Indent
This will smart indent all selected lines or the entire document if nothing is selected. For selected lines, it will first-round first non-whitespace line to the nearest integer multiple of four spaces, and then it will begin the smart indent from there. When doing the entire document, it will move to remove all leading whitespace on the first non-whitespace line, and then continue from there. It uses a four-space indent. - CTRL+W : Close the tab of the current simulation file where the cursor is
- CTRL+ Page Up : Swap to tab on the right
- CTRL+ Page Down : Swap to tab on the left
- CTRL+ Shift + N : Creates new tab that matches the type of the current tab.
- CTRL+ = : Increase font size.
- CTRL+ - : Decrease font size.
- CTRL + 0 : Reset font to default.
The above features are also available in the context menu when you right-click in the script file editor.
Hotkeys for cursor positioning
- HOME/END : Move to the beginning/end of the current line
- SHIFT+HOME/END : Move to beginning/end of line while selecting
This will move the cursor from the current position to the beginning or end of the line of code while toggling the selection of the cursor locations. ie. if the text is not selected it will become selected, and if it is already selected it will be de-selected. - CTRL+HOME or SHIFT+CTRL+HOME : Move the cursor to the very beginning of the script
- CTRL+END or SHIFT+CTRL+END : Move the cursor to the very end of the script
Debugger user interface
The debug mode is activated by clicking . It allows users to set breakpoints in the Script Editor, start a debugging session, visually see relevant information and the current workspace during a break, and navigate through a debugging session.
Continue debugging
Runs script until next breakpoint.
Stop debugging
Stops the execution of the script.
Step debugger
Execute the current line of code, then break on the next line of code.
Detach debugger
Will no longer stop on breakpoints. Execution of script will run to completion.
Breakpoint behavior
-
Breakpoints are added/removed to the line bar by clicking to the left of the line number.
-
Breakpoints are marked by a red circle.
-
The current breakpoint is marked by a yellow triangle.
[[NOTE:]] The debugger does not support multi-line code. For example:
x = 1 + 2+ 3 +
4 + 5+ 6;