Script Editor

The Script Editor is used to edit scripts. Cognex Designer provides a powerful scripting environment using Microsoft C# .NET, allowing you to write standard C# .NET code and have it executed within the project.

The Script Editor contains the following buttons and user interface elements:

  • (Compile the current script): Checks the script written in the editor, and compiles it if there are no errors. The hotkey for this button is F6.
  • (Delete the current script): Deletes the current script. The deletion is preceded with a confirmation prompt.
  • (Comment out the selected lines): Comments out the active line (that is, where the prompt is located), or the selected line(s). Clicking the button multiple times when the same line(s) are selected adds multiple comment tags to the selected line(s). The hotkey for this button is Ctrl + K.
  • : Fixes compilation errors that can be automatically resolved by the Script Editor (such as missing using directives or assembly references). The Auto-Fix Errors button appears only if the Script Editor encountered any compilation errors that it can automatically fix.
  • (Uncomment the selected lines): Uncomments the selected comment line(s). If commented and non-commented lines are selected simultaneously, it only changes the commented line(s) to uncommented. Clicking the button has no effect on uncommented lines. The hotkey for this button is Ctrl + U.
  • / : Indicates whether the script has been successfully compiled (Success), or whether the Script Editor detected an error during compilation (Compile Error).
Tip: Besides the above hotkeys, you can also use Ctrl + F and Ctrl + H to respectively Find or Replace content in the script.

When the Script Editor is open, the Toolbox is similar to the Tags Window, but it lists $ Functions as well as Tags. You can drag and drop items from the Toolbox into the script to use them.

The Properties window contains a list of the Using statements being used by the code (see the Calling External Code and Using Statements topic for more information), and a link to the Script Reference dialog (see the Adding References topic for more information), which lists all the libraries and DLLs that the script is currently referencing, and can reference.

Note: For more details on how to develop scripts with the Script Editor, see the Scripting topic.