Scripts

Scripts are Manifold programs written in an ActiveX or .NET programming language that is installed on the computer system.

Visual Basic Scripting Edition is the default ActiveX scripting language used with Manifold; however, Jscript (Microsoft's implementation of Javascript) is also frequently used. Scripts may be written in any language for which an ActiveX scripting engine is available. Some users, for example, prefer to write scripts in Python or Perl using ActiveX scripting engines for those languages that are available from third party suppliers.

Documentation and technical support for scripting in Manifold uses VBScript with occasional examples in Jscript. The use of other languages is respected but is not covered by documentation or technical support. VBScript and Jscript are covered since these are standard Microsoft languages that may be redistributed by manifold.net with Manifold.

Manifold also supports scripting in Microsoft .NET languages such as C#, Jscript.NET and VB.NET.

Scripts are components that appear in the project pane.

When a script window is open, the Script menu is available:

Open Form
Open the form associated with this script.
Open Table
Open the table associated with this script.
Run
Run the script
Run under Debugger
Run a script under control of the debugger. Available if the Debugger is installed.
Pause
Pause execution of a script. Available if the Debugger is installed.
Stop
Stop execution of a script. Available if the Debugger is installed.
Step Into
Step over a routine. Available if the Debugger is installed.
Step Out
Step into a routine. Available if the Debugger is installed.
Step Over
Step out of a routine. Available if the Debugger is installed.
Language
Specify a scripting language. Available choices will include all ActiveX scripting engines installed on the computer system.

Use keyboard shortcuts to set and clear breakpoints. Click on a text line in the script window and then press F9 to toggle a breakpoint at that line.

Example

Choose File - Create - Script to create a new script component in the project pane.

images/dlg_create_script.png

The Create Script dialog box will allow us to name our new script, provide an optional description and choose a language (default choices being C#, Jscript, Jscript.NET, VB.NET and VBscript). If a .NET language is selected, we can check the Add references for standard .NET modules box.

images/icon_script.png The new script component will appear in the project pane marked with a script icon. Clicking on the component to highlight it will provide information about script in the project pane status bar, including the size of the script and the language used.

Double-click the script component to open it in a script window. The new script will appear with startup text appropriate for that language, by default showing a simple script to print "Hello, World!" to a message box.

Running a Script

Suppose we have created a VBscript script. The default text in the script will be:

Sub Main

Application.MessageBox "Hello, World!", "Script"

End Sub

images/btn_scripts_run.png Press the Run button in the Tools toolbar to run the script. We can also click onto the script component in the project pane to highlight it and then press the Run button in the project pane.

images/sc_msgbox_hello.png

A message box appears with our desired message. Press OK to close the message box.

If we had used a .NET language like VB.NET, whenever we run the script it will first be compiled, which may add a delay before the script launches in the case of large scripts. We can avoid this delay by using the Script - Compile to DLL command to compile the script into a DLL.

Any errors detected during compilation of a .NET script will be displayed in the Errors pane.

Note: If we have purchased the Debugger option for Professional Edition or if we are running Enterprise Edition (which includes the Debugger) we can run scripts using the Debugger. See the Debugger topic for more information.

Saying Hello in C#

The C# version of "Hello, World" is:

images/sc_script_csharp_hello.png

Saying Hello in Jscript

The Jscript version of "Hello, World" is:

images/sc_script_jscript_hello.png

Saying Hello in Jscript.NET

The Jscript.NET version of "Hello, World" is:

images/sc_script_jscriptnet_hello.png

Saying Hello in VB.NET

The VB.NET version of "Hello, World" is:

images/sc_script_vbnet_hello.png

Saying Hello in VBscript.NET

The VBscript version of "Hello, World" is:

images/sc_script_vbscript_hello.png

Note that the above scripts use the built-in Application object.

Saying Hello in PythonScript and PerlScript

Many languages are available as ActiveX scripting languages for Windows. For example, installing the Active State Python or Perl distributions (free as of this writing from http://www.activestate.com) will add Python and Perl scripting capabilities to Manifold. As with Jscript, scripts in these languages use the built-in Application object.

PythonScript:

def Main():

Application.MessageBox("Hello, World!")

PerlScript:

sub Main {

$Application->MessageBox("Hello, World!");

}

Some users prefer scripting in Python or Perl to scripting in VBScript or Jscript; however, Manifold technical support is able to support only VBScript, Jscript and the .NET languages.

Adding Scripts as Toolbar Buttons or Menu Commands

Scripts (which may call external COM objects) may be added as custom toolbar buttons or menu items. See the Add-Ins topic for information on adding new toolbar buttons or menu commands.

Script Window Keyboard Shortcuts

Script windows support well-known Windows keyboard shortcuts, including those often used in Windows programming editors:

CTRL-A
Select All
CTRL-I
Invert Selection.
CTRL-X
Cut selected text and copy to the Clipboard.
CTRL-C
Copy selected text to the Clipboard.
CTRL-V
Paste text contents of the Clipboard.
CTRL-L
Delete current line.
CTRL-J
Comment out selected text.
SHIFT-CTRL-J
Uncomment selected text.
CTRL-M
Convert selected text to lower case.
SHIFT-CTRL-M
Convert selected text to upper case.
CTRL-Insert
Equivalent to CTRL-C. An old Windows shortcut kept for compatibility.
SHIFT-Insert
Equivalent to CTRL-V. An old Windows shortcut kept for compatibility.
Insert
Toggles insert / overwrite mode.
CTRL-Z
Multi-level Undo.
CTRL-Y
Multi-level Redo.
Shift-Delete
Same as CTRL-X or Cut.
ALT-Backspace
Same as CTRL-Z or multi-level Undo.

CTRL-J and CTRL-SHIFT-J comment / uncomment commands will automatically switch between commenting styles based on the language specified for the script window with Script - Language . Works for VBscript, Jscript, C#, JScript.NET, VB.NET, PERL, and Python.

Example: Referencing a Script that has been Compiled into a DLL

The Script - Compile to DLL command may be used with .NET languages to avoid the slight compile delay when the .NET script is compiled before running. The command may also be used to compile .NET language scripts into DLLs for future use in other scripts, as in the following example:

  1. Launch Manifold. Create a new project.

  2. Create a new script using VB.NET. Enter the following script text:

Imports Manifold.Interop

Public Class Test

Public Shared Function ComponentCount(D As Document) As String

Return D.ComponentSet.Count

End Function

End Class

  1. Choose Script - Compile to DLL and save the DLL into the Manifold installation folder (that is, the Windows folder into which Manifold System itself was installed, by default, C:\Program Files\Manifold System).

  2. Create another script using VB.NET. Invoke Script - References. Click New, and select the compiled DLL created in the above steps. Enter the following script text:

Imports Manifold.Interop.Scripts

Class Script

Shared Sub Main

Context.Application.MessageBox( _

Test.ComponentCount( _

Context.Application.ActiveDocument), "Script")

End Sub

End Class

Invoke Script - Run. The script will show the number of components in the currently opened MAP file.

It is, of course, possible to place a compiled DLL into a folder that is different from the Manifold installation folder, but then we would have to make sure the .NET loader will be able to find both:

a) the compiled DLL when running a Manifold script that refers to it (usually achieved by either signing the compiled DLL and putting it into the global assembly cache, or by putting the compiled DLL into a folder mentioned in the PATH environment variable), and

b) all Manifold DLLs required when loading the compiled DLL (usually achieved by using a custom configuration file).

See Microsoft documentation on .NET languages for details, including MSDN. In particular see this MSDN topic (URL current as of the time of writing) for more information:

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconhowruntimelocatesassemblies.asp

Notes

Attempting to save or close a project in the middle of an executing script will display a warning message. Stop any executing scripts before saving or closing a project.

Script windows support multi-level Undo / Redo. One can CTRL-Z (Undo) backwards through many changes and CTRL-Y (Redo) forwards to redo many Undo operations.

Script windows will show their contents using different colored font for different parts of the script. This is called syntax highlighting and is a helpful way of identifying typographical errors. Fonts used in script windows may be specified in Tools - Options. However, fonts used with script windows will be restricted to fixed-width fonts.

See Also

Script Examples

Forms

Programming Manifold

Scripting Reference

See the Active Columns topic for a cool use of scripts within tables. See Active Columns using VBScript and Active Columns using Jscript for examples using active columns and script functions written in VBScript and Jscript.

See the Forms and Scripts topic for examples of using scripts together with forms.

See the Debugger topic if you are using Enterprise Edition or if you have purchased the Debugger option for Professional Edition.

Back to Manifold Home Page