Writing Scripts
This section provides instructions on writing, editing, or debugging scripts in the Desigo CC script editor. For background information, see Script Editor Workspace.
Prerequisites:
- System Manager is in Engineering mode.
- System Browser is in Application View.
Create a New Script Object
Do this procedure to create a new script from scratch.
- (Optional) Create the subfolder where you want to place the new script.
- In System Browser, select Applications > Logics > Scripts.
- The Script Editor tab displays.
- Click Save As .
- In the Save Object As dialog box, select the main Scripts folder or any subfolder under it as the destination where you want to save the new script:
a. Enter a name and description.
b. Click OK.
- The new script object is added to System Browser and is enabled by default.
Edit the Code of a Script
You can enter or edit the code of a script in Script Editor tab.
- At least one script object is available under Application > Logics > Scripts. See Create a New Script Object above, or Importing a Library Script into the Project, or Importing Scripts into the Project from a File.
- In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
- The Script Editor tab displays.
- In the Editor expander, enter or modify the script code. You can also copy-paste code into this area. Refer to the Scripts Syntax Reference as needed.
- The Error List expander displays any detected syntax errors as you type.
- Fix any errors reported in the Error List expander. You can use the following controls to help you examine the code:
- Click Expand names to expand a block of text to modify.
- Click Show line number to display line numbers.
- Use CTRL+F to jump to a specific line number.
- Click Save .
Test or Debug a Script in Script Editor
You can test or debug an existing script in the Script Editor tab.
- The script you want to test is available under Application > Logics > Scripts and enabled for execution.
- In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
- In the Script Editor tab, open the Editor expander to display the code of the script.
- Use the following toolbar controls as needed to test the script:
- Start , or Start with if the script has parameters, to run the script starting from the current position.
- Step into , Step over , and Step out to step through the script line by line or method by method.
- Stop to halt execution of the script and go back to the beginning.
- Restart to run the script again from the beginning.
- The output of the script (if any) displays in the Console expander. The Operation tab displays the status of the script (
Idle
,Running
, orStepping
).
Search for Text or Jump to a Line Inside a Script
To help you move around a script, you can use shortcut keys to find a specific text string, or to jump to a specific line number.
- In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
- The Script Editor tab displays.
- To search for text in the script code:
a. Press CTRL+F.
b. In the Quick find field, enter the string to search for. This results in the selection of the first match while the others are highlighted in the Editor expander.
c. Click Find Next or press F3 to go to the next match.
d. Press CTRL+F again to quit the search and hide the Quick find field.
- To jump to a specific line of code:
a. Press CTRL+G.
b. In the Go to field, enter the code line number. This will position the cursor on the first match.
c. Click Go to move the cursor to the next match.
d. Press CTRL+G again to quit and hide the Go field.
Set the Additional Properties of a Script
You can also set some additional properties and behaviors for the script that you are working on. For background information, see Execution of Scripts.
- In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
- In the Extended Operation tab, you can do the following:
- Next to Notes, click Change, enter your comments/remarks for the script, and click Send.
- Next to Version, click Change, enter the script version (major.minor), and click Send.
- Next to Log, select from the drop down list how to manage the logging of Activity Status changes (Always, Never, or On failure), and click Change.
- Next to Timeout, click Change, enter the maximum allowed execution time, and click Send: If the script fails to terminate within this time, it will be automatically stopped.
- Click Enable Signature Validation to activate additional checks of the signature validation on newly created or imported scripts.
NOTE: Before enabling the signature validation you must configure the trusted certificate authorities.