220.127.116.11 From Script and Command Window
Script Window and the (newer) Command Window.
Each window can execute single or multiple lines of script.
Two Windows exist for direct execution of LabTalk: the (older)
- The Command Window has a prompt and will execute all code entered at the prompt.
- The Script Window has only a cursor and will execute highlighted code or code at the current cursor position when you press Enter.
- Both windows accept Ctrl+Enter without executing. When using Ctrl+Enter to add additional lines, you must include a semicolon (;) at the end of the statement for multiple-line execution.
- In the Script Window, you can use the menu item Edit: Insert newline to insert a new line; You can also turn Script Execution off or on in the Edit menu by checking or unchecking Script Execution.
- Both the Script Window and Command Window support Intellisense for auto-completion of X-Functions; only the Command Window includes a command history and recall of line history (Up and Down Arrows).
- The Script Window allows for easier editing of multiline commands and longer scripts.
Origin 2023 added a Scintilla-based Script Window with support for Unicode, auto-completion, syntax-coloring, font-size control (zoom using Ctrl + mouse). The change should improve usability, particularly for those with 4k monitors. Roll back to the original Script Window by setting @NSW=0.
Below is an example script that expects a worksheet with data in the form of one X column and multiple Y columns. The code finds the highest and lowest Y values from all the Y data, then normalizes all the Y's to that range.
// Find the lowest minimum and the highest maximun
double absMin = 1E300;
double absMax = -1E300;
if(absMin > stats.min) absMin = stats.min;
if(absMax < stats.max) absMax = stats.max;
// Now normalize each column to that range
wcol(ii)-=stats.min; // Shift to minimum of zero
wcol(ii)/=(stats.max - stats.min); // Normalize to 1
wcol(ii)*=(absMax - absMin); // Normalize to range
wcol(ii)+=absMin; // Shift to minimum
To execute in the Script Window, paste the code, then select all the code with the cursor (selected text will be highlighted), and press Enter.
To execute the script in the Command Window, paste the code then press Enter. Note that if there were a mistake in the code, you would have it all available for editing in the Script Window, whereas the Command Window history is not editable and the line history does not recall the entire script.
Origin also has a native script editor, Code Builder, which is designed for editing and debugging both LabTalk and Origin C code. To access Code Builder, enter ed.open() into the script or command window, or select the button from the Standard Toolbar.
The font in Script Window can be customized in this way:
- Open the Origin.ini file in User Files Folder, search for the [font] section: paste the contents below in [font] section.
- Restart the Origin and check the Script Window again, the font and size both changed.
ScriptWindowFaceName=Times New Roman
For more charset value, see http://msdn.microsoft.com/en-us/library/cc250412.aspx