Script Selector

You can access Internal Scripts using the Script Selector dialog. To access this dialog, use the menu Document>Scripts.

Click on the image below to learn more about the various sections of this dialog.

1. Scripts

A list of scripts in the Site database that you have access to.

2. Filter

Applies the entered text as a dynamic filter to the list of scripts, allowing you to find a specific script easily when there is a large number of scripts in your Site database.

3. Compile

Compile gathers all of the Script code and Module code and checks the code for syntax errors or missing assemblies/modules that are referenced.

4. Execute

Executes the script (if the Compile is successful).

5. Status

Displays information on the status of the script. If a script has been compiled or executed, you can open the Status dialog to see more information on what happened during those operations.

6. Include

Select one or more Include options to filter which scripts are displayed in the Script Selector.

7. New

Creates a new Script. Select a scripting language and click OK to open the Script Properties dialog.

8. Edit

Opens the Script Properties dialog for the selected script.

9. Refresh

Reloads the dialog contents. You may need to click Refresh while a script is executing to get the latest script status.

Script Properties

The Script Properties dialog is used to create and modify internal scripts. Click on the image below to learn more about the various sections of this dialog.

1. Label

Enter a label for the script.

2. Description

Enter a description for the script. This field is optional.

3. Declarations

Script declarations are code that is expected up front when the script is compiled for the language used. Writing code in C# or Visual Basic involves declaring up front expected code such as Visual Basic Imports or C# using statements.

For example:

Visual Basic

C#

Imports System

Imports CM4D.Scripting

Imports CM4D

Imports Microsoft.VisualBasic

using System;

using CM4D.Scripting;

using CM4D;

Declarations in a Script Module must be copied to the Script level Declarations.

4. Script Access

Script Access determines which users have access to the script. There are three levels that can be used to determine access:

·        Public - available to all users

·        Group - available to all users that belong to the selected group

·        User - only available to the user that created the script

5. Timeout

Timeout is the interval (in minutes) after which the script will be stopped. The Timeout property prevents potentially infinite loops, and is really the only ‘safety’ mechanism provided for internal scripts.

6 Compile

Compile gathers all of the Script code and Module code and checks the code for syntax errors or missing assemblies/modules that are referenced.

7. Execute

Executes the script (if the Compile is successful).

8. Entry Code

The Entry Code is the entry point for the script execution. This requires some very specific code that defines the entry point, and any user-defined code is inserted after this. The required code, or shell, is inserted automatically (conforming with the programming language selected) when a new script is created:

 

Visual Basic

C#

Start Code

Public Class CM4DScript

    Public Sub Execute(cm4dDoc as Cm4DScriptingDoc)

public class CM4DScript

{

    public void Execute(Cm4DScriptingDoc cm4dDoc)

    {

End Code

        cm4dDoc.EndScript()

    End Sub

End Class

        cm4dDoc.EndScript();

    }

}

9. Modules

Script Modules are optional, as all script code can be defined in the Declarations and Entry Code. However, Modules provide a way to build reusable code that can be referenced by and included in multiple scripts.

To include a script Module, click Add. In the Script Module Selector, either create a new Module or highlight an existing Module from the list, and then click Select.