Scripts

icon_script.png Scripts allow us to write programs for execution within Manifold using a variety of built in and supported languages.    Scripts can be edited when they are opened in a Script window.  In addition, JavaScript, IronPython and IronRuby can be edited and executed from the Command window, using the Command window as a REPL (Read-Eval-Print Loop) console.   Add-ins to extend Manifold with new commands can also be written using scripts.

 

tech_yoshi_sm.png

Must read info:   All programmers should review the API Documentation online.    The API Documentation provides total details on the API and also provides hundreds of examples, many of which are provided side-by-side in three versions, in C#, in VBScript and in IronPython, for example:

 

il_api_eg_csharp.png

il_api_eg_vbscript.png

il_api_eg_ironpython.png

The above example connects to an IMG file and retrieves a table that contains image data. The file format can be ERDAS IMG, ENVI IMG, IDRISI IMG or any other supported technology that matches the filename.

 

To create a script:

 

 

Running a script:

 

 

For tips on editing the text of scripts in the Command Window, see the Editing Queries, Scripts and Comments topic.

Languages

Manifold allows scripting in eleven different scripting languages by supporting them for use within Script windows.  Six scripting  languages are always available for use in every Manifold installation without requiring any additional installation of any kind, either because they are built in to Manifold (Javascript) or because they are automatically available as a result of Microsoft facilities that are required for any Manifold installation.

 

Two additional languages, IronPython and IronRuby, are automatically supported by the Command Window when they are installed.   Five more languages, F#, PerlScript and PythonScript, are supported when they are installed.  

 

Always available languages:

 

 

JavaScript using the Google V8 engine is built into Manifold and is the recommended default.  The other always available languages are provide by Microsoft COM/.NET, which are required for Manifold installation.

 

Additional languages built into the Command Window:

 

 

IronPython and IronRuby are supported by the Command Window just like the built in JavaScript engine, but they are not part of  Manifold installations.   IronPython and IronRuby are installed separately.  See the example below for a typical IronPython installation procedure.

 

Additional Supported Languages:

 

 

Manifold understands and supports the above languages for scripting using script components.

 

Default Scripts

Following are examples of the default "Hello, World!" scripts which are created when we create a new script using the various languages used by Manifold.   The default scripts write the "Hello, World!" text to a log window that is automatically opened when the script is executed.  In addition to illustrations the code is included below as text to enable copy and pasting from this documentation.

C#

il_script_csharp.png

Code:

 

// C#

 

class Script

{

 

static Manifold.Context Manifold;

static void Main()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

}

 

F#

il_script_fsharp.png

Code:

 

// F#

//

// Note: running script requires F# and F# PowerPack (FSharp.Compiler.CodeDom.dll)

 

module Script

    let mutable Manifold: Manifold.Context = null

    let Main() =

        Manifold.Application.Log("Hello, World!")

        Manifold.Application.OpenLog()

 

IronPython

il_script_ironpython.png

Code:

 

# IronPython

#

# Note: running script requires IronPython (IronPython.dll)

 

def Main():

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

 

IronRuby

il_script_ironruby.png

Code:

 

# IronRuby

#

# Note: running script requires IronRuby (IronRuby.dll)

 

def Main()

manifold.application.log('Hello, World!')

manifold.application.open_log()

end

 

JavaScript

il_script_javascript.png

Code:

 

// JavaScript

 

var Main = function()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

JScript

il_script_jscript.png

Code:

 

// JScript

 

var Main = function()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

JScript.NET

il_script_jscriptnet.png

Code:

 

// JScript.NET

 

class Script

{

 

static var Manifold: Manifold.Context;

static function Main()

{

Manifold.Application.Log("Hello, World!");

Manifold.Application.OpenLog();

}

 

}

 

PerlScript

il_script_perlscript.png

Code:

 

# PerlScript

#

# Note: running script requires ActivePerl

 

sub Main

{

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

$Manifold->Application->OpenLog();

}

 

PythonScript

il_script_pythonscript.png

Code:

 

# PythonScript

#

# Note: running script requires ActivePython

 

def Main():

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

 

VB.NET

il_script_vbnet.png

Code:

 

' VB.NET

 

Class Script

 

Shared Manifold As Manifold.Context

Shared Sub Main()

Manifold.Application.Log("Hello, World!")

Manifold.Application.OpenLog()

End Sub

 

End Class

 

VBScript

il_script_vbscript.png

Code:

 

' VBScript

 

Sub Main

Manifold.Application.Log "Hello, World!"

Manifold.Application.OpenLog

End Sub

 

Inline Scripts

Queries can include inline scripts using the SCRIPT statement.  Inline scripts provide a way to use script functions in a single self-contained query component.

 

Example: Add a computed field that uses an inline script to set insert date for each record:

 

ALTER TABLE t (

  ADD insertdate DATETIME

    WITH

[[

 

SCRIPT funcs ENGINE 'c#' [[

  class Script

  {

    static System.DateTime F() { return System.DateTime.Now; }

  }

]];

FUNCTION currentdate() DATETIME AS SCRIPT INLINE funcs ENTRY 'Script.F';

 

]]

    AS [[ currentdate() ]]

);

 

After running the above query, existing records in the table will get the current datetime.   If we wait a minute or so to allow the datetime to visibly change and then insert a new record,  either manually or using INSERT, it will get the new, current datetime value.

 

Example: Installing IronPython 2.7.8

Manifold expert Tim Baigent has contributed the following advice in a thread in the Manifold user forum:

 

To add IronPython to Manifold Release 9:

 

 

 

 

 

 

mklink /j "C:\Program Files\Manifold\v9.0\shared\IronPythonNet278" "C:\Program Files\IronPython 2.7"

 

 

mklink /j "D:\manifold-9.0.166.6-x64\shared\IronPythonNet278" "C:\Program Files\IronPython 2.7"

 

 

Important:  the commands above should be all on one line.

 

This creates an NTFS hard link (or directory junction) for the IronPython folder inside the Manifold folder, without making new copies of any files. Manifold sees the full IronPython installation exactly as if it were contained in the Manifold "shared" subfolder. If you later update the IronPython installation, Manifold will see the new version.

 

Comments

 

IronPython 2.7.8 was released in February 2018.  The main changes which are relevant to setup:

 

 

Thank you, Tim!

Notes

Agnosticism - Manifold is completely agnostic about programming languages, as can be seen by the wide range of languages which are directly supported for scripting in Manifold.  JavaScript is built in for convenience and to leverage the ubiquity achieved by JavaScript as a result of Internet.  The V8 engine was selected as a high quality and fast JavaScript engine that is compatible with Manifold parallelism and which would fit within an .msi installation.    The Manifold Command Window by default supports both IronPython and IronRuby to provide stylish alternatives to JavaScript.  C#, JScript, JScript.NET, VB.NET and VBScript are supported and are always available because of the Microsoft infrastructure required for a Manifold installation.   Manifold also supports F#, PerlScript and PythonScript, which are easy to install if desired.

 

See Also

Queries

 

Editing Queries, Scripts and Comments

 

Tools - Add-ins

 

Command Window

 

Example: Run JavaScript in the Command Window - How to run a simple V8 JavaScript script in the Command window.

 

Example: VBScript to Create Locations from a Table - Use VBScript to take a table where each record has a name, scale, latitude and longitude and for each record create a Location component in the project.

 

SCRIPT

 

For information on scripting, see the Manifold API Documentation website.