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. The Info pane will report the language used 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. Using Manifold Commander, scripts can be automated, for example, launched every day at a given time, to automate GIS, DBMS, and ETL tasks.
We can also write a temporary script in a limited selection of languages that are installed, which will appear as choices of <scripting language> in the View - New Command Window command. See the discussion in the View - New Command Window topic.
New scripts created within the Command Window disappear when the Command Window is closed. To save the script, choose Edit - Save as Script.
For tips on editing the text of scripts in the Command Window, see the Editing Queries, Scripts and Comments topic.
Running a script:
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:
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.
Running a script:
For tips on editing the text of scripts in the Command Window, see the Editing Queries, Scripts and Comments topic.
Manifold allows scripting in ten different scripting languages by supporting them for use within Script windows.
Five 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 (installation is easy). Three more languages, F#, PerlScript and PythonScript, are supported when they are installed. One more language, Google's V8 implementation of Javascript, is easy to install and use as well.
C#
JScript
JScript.NET
VB.NET
VBScript
The always available languages are provide by Microsoft COM/.NET, which are required for Manifold installation.
IronPython
IronRuby
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.
F#
PerlScript
PythonScript
Manifold understands and supports the above languages for scripting using script components.
When using the New Script dialog to create a new script, a COM, or .NET annotation indicates the type of each language:
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#
class Script
{
static Manifold.Context Manifold;
static void Main()
{
Manifold.Application.Log("Hello, World!");
Manifold.Application.OpenLog();
}
}
// 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
#
# Note: running script requires IronPython (IronPython.dll)
def Main():
Manifold.Application.Log("Hello, World!")
Manifold.Application.OpenLog()
# IronRuby
#
# Note: running script requires IronRuby (IronRuby.dll)
def Main()
manifold.application.log('Hello, World!')
manifold.application.open_log()
end
// JScript
var Main = function()
{
Manifold.Application.Log("Hello, World!");
Manifold.Application.OpenLog();
}
// JScript.NET
class Script
{
static var Manifold: Manifold.Context;
static function Main()
{
Manifold.Application.Log("Hello, World!");
Manifold.Application.OpenLog();
}
}
# PerlScript
#
# Note: running script requires ActivePerl
sub Main
{
$Manifold->Application->Log("Hello, World!");
$Manifold->Application->OpenLog();
}
# PythonScript
#
# Note: running script requires ActivePython
def Main():
Manifold.Application.Log("Hello, World!")
Manifold.Application.OpenLog()
' 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
Sub Main
Manifold.Application.Log "Hello, World!"
Manifold.Application.OpenLog
End Sub
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.
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.
Microsoft has moved IronPython to github as an open source project. Download the .msi from the IronPython 2.7.9 github page.
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
It is highly likely that future builds of Manifold may automatically detect an IronPython installation and automatically use that without the need to Copy and Paste the above .dll files into the Manifold installation's extras folder.
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. 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. Google's V8 implementation of Javascript is also easy to install and use.
See the Manifold API Documentation website.
Editing Queries, Scripts and Comments
Example: Create and Run a JScript.NET Script - How to create and run simple JScript.NET scripts.
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.