Executing Scripts

This section provides instructions on executing scripts in Desigo CC, both manually and automatically.

 

Reference: For background information, see Execution of Scripts.

 

Prerequisites:

  • Desigo CC is configured to integrate scripting functionality.
  • System Browser is in Application View.

 

Make Scripts Available for Execution

The scripts available for execution in a project are located under the folder Applications > Logics > Scripts. You can add scripts to this folder in the following ways:

 

Enable or Disable Scripts

When you create or import a script into Application View, it is automatically enabled by default. This means that all authorized users will be able to start it manually and also that it will start automatically if configured to do so (at project startup, or through a reaction). You can manually enable/disable individual scripts, or all the scripts in a folder at once.

Enable or Disable an Individual Script

  1. In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
  • In the Operation tab, the Operational Status property indicates whether the script is Enabled or Disabled).
  1. Click Enable or Disable.
  • The Operational Status property updates accordingly.

Enable or Disable all the Scripts in a Folder

  • Select Applications > Logics > Scripts > [scripts folder].
  • In the Operation tab, alongside Operational Status, click Enable All or Disable All.

 

NOTE 1:
When you disable a script, Desigo CC generates an event. This event is automatically cleared when you re-enable the script.

NOTE 2:
If a script is saved with JavaScript syntax errors, its operational status is Configuration Error and Desigo CC generates an event. In this condition, it is not possible to execute the script. When the error is fixed, and the script is saved again, the operational status becomes Disabled. You must enable this script before being able to execute it.

 

Manually Execute or Stop Scripts

You can manually start, stop, or restart scripts from the Operation tab.

Start, Stop or Restart an Individual Script

  1. In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
  1. In the Operation tab, depending on the value of the Activity Status property, you can do one of the following:
  • Click Start to execute the script. Available if the script is currently Idle.
  • Click Stop to terminate the script. Available if the script is currently Running.
  • Click Restart to stop the script and start it again. Available if the script is currently Running.
  • The Activity Status of the script updates accordingly.

Start, Stop, or Restart all the Scripts in a Folder

  1. In System Browser, select Applications > Logics > Scripts > [subfolder].
  1. In the Operation tab, do one of the following:
  • To start all the scripts, click Start All.
  • To terminate the execution of all the scripts, click Stop All.
  • To terminate and restart the execution of all the scripts, click Restart All.

 

Start a Script with Parameters

Scripts can be written so that they accept parameters (see Preparing a Script to Start with Parameters). This makes it possible to execute the same script on different objects.

  • A script was configured to accept parameters. It is enabled, and its Status is Idle.
  1. In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
  1. Click Start with parameter.
  1. In the Parameter field, enter the parameter required by the script.
  1. Click OK.
  • The value of the Status property becomes Running.

 

Set a Script to Execute Automatically on Project Startup

You can configure a script so that it executes automatically when the Desigo CC project starts up. Since such a script is not started manually by any user, you will also need to specify with what user credentials the script should run.

  • System Manager is in Engineering mode.
  • The script you want to start automatically is available and enabled for execution.
  1. In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
  1. In the Script Editor tab, click Set Execution Credentials .
  1. In the Script Editor dialog box, enter a user name and password of the user that will execute the script under credentials.
    NOTE: You must choose a user with the appropriate privileges.
  1. Click OK.
  • If the credentials provided are valid and the user is enabled, the username will be set for the script manual or automatic execution.
  1. In the Operation tab, alongside Execution Mode:
    a.
    Select Automatic.
    b. Click Change.
  • The script will be executed automatically on project startup, using the credentials that you specified.

If the execution credentials are later cleared from this script, or if that user is removed from the project, the Execution Mode of the script will be set back to Manual.

 

Disable Automatic Execution of the Script

If you later want to disable automatic execution of this script at project startup, do the following:

  1. In System Browser, select Applications > Logics > Scripts > [scripts folder] > [script].
  1. in the Operation tab, alongside Execution Mode:
    a. Select Manual.
    b. Click Change.
  • The script will no longer be executed automatically on project startup, but it can still be started manually.

 

Set the Execution Credentials for a Script

By default, scripts execute with the credentials of the logged on user. However, you can also configure a script to start using credentials different from the default ones. Basically, this is necessary for scripts configured to execute automatically when the Desigo CC project starts up.

  • System Manager is in Engineering mode.
  • One or multiple scripts are available and enabled for execution.
  1. In System Browser, select Application View.
  1. Select Applications > Logics > Scripts > [scripts folder] > [script].
  • The Script Editor tab displays.
  1. Click Set Execution Credentials .
  1. In the Script Editor dialog box, enter user name and password of the user that will execute the script under credentials.
    NOTE: You must choose a user with the appropriate privileges.
  1. Click OK.
  • When the credentials are valid, and the user is enabled, the username will be set for the manual or automated execution of this script.
  • With invalid credentials, the following message displays in the Script Editor status bar: Error while setting execution credentials.

 

If the user is removed from the project after the Execute under Credentials property is set, an error is traced in the Trace Viewer, and the credentials are cleared from the script.

 

Clear the Execution Credentials for a Script

To reset the script credentials to the default settings, do the following:

  1. Select Applications > Logics > Scripts > [scripts folder] > [script].
  • The Script Editor tab displays.
  1. Click Clear Execution Credentials .
  • The user credentials are cleared. The script will once again execute with the credentials of the logged-in user.

NOTE: If the script was configured to execute automatically on project startup, clearing the credentials will also set its Execution Mode back to Manual.

 

[Example] Automate a Script with a Reaction

In this example, we will configure Desigo CC to automatically start a certain script, on Saturdays at 8 am. To do this, you will configure a reaction that invokes that script at the specified time. For background information about reactions and related conditions, see Reactions and Time and Organization Mode Conditions in Triggers and Filters.

  • The reaction license is installed.
  • The script that you want to automate is enabled for the execution.
  • System Manager is in Engineering mode.
  • Select Applications > Logics > Reactions.
  • The Reaction Editor tab displays.

Set the When the Script is Invoked

  1. In the Triggers expander, open the Time and Organization Mode expander.
  • The expander initially contains a single row with time and date set to Always.
  1. Click the first row in the Time and Organization expander.
  1. In the Effective Days column:
    a. Open the drop-down list and set Recurrence: Weekly.
    b. Select the frequency Every: 1 week.
    c. Clear the check boxes for all days except Saturday.
  1. In the Time column:
    a. Clear the Begin of day check box.
    b. In the Set Start Time field, enter 08:00:00 AM.
    c. Clear the Set End Time check box.

Select the Script to Invoke

  1. In the Output expander, open the Action expander.
  1. In System Browser, select the Manual navigation check box.
  1. Select Applications > Logics > Scripts.
  1. Drag the script into the empty area of the Scope/Target column in the Action expander.
  • The Action expander displays a new instruction (row) that invokes the script.
  1. Configure the other fields in the row: set Property to Status and Command to Start.

Save the Reaction

  1. Open the General Settings expander.
  1. In the Notes field, enter a description (for example, Automatically start the script every Saturday morning at 8 am).
  1. Click Save As .
  1. In the Save Object As dialog box, select the main Reactions folder or any subfolder under it as the destination where you want to save this reaction.
    a. In the Name field, enter Automatic Weekly Script.
    b. Click OK.
  • The script is now automated and will start based on when the configured time-related conditions occur.

 

[Example] Automate Scripts with a Macro

In this example, we will create a macro that automatically invokes a set of scripts one after the other. For background information about macros, see Macros.

  • System Manager is in Engineering mode.
  • The scripts that you want to automate are enabled for the execution.
  1. In System Browser, select Applications > Logics > Macros.
  • The Macro tab displays.
  1. Select the Manual navigation check box.
  1. Select Applications > Logics > Scripts.
  1. Drag the scripts from System Browser into the empty area inside the Macro tab.
  • For each script, a new instruction row is created.
  1. For each instruction, configure the other fields in the row: set Property to Status and Command to Start.
  1. (Optional) In the Initial Delay field, set the delay before the command is sent out.
  1. Click Save As .
  1. In the Save Object As dialog box, select the main Macros folder or any subfolder under it as the destination where you want to save the new macro.
    a. In the Name field, enter Automatic Scripts Run by Macro.
    b. Click OK.
  • When this macro is invoked, the scripts are now automated and will be started.