Add-ins allow us to extend the capabilities of Manifold. Add-ins are programs written in languages supported by Manifold. When Manifold launches, the system searches Manifold's ~\bin, ~\bin64 and ~\shared folders for DLL files and scripts, loading scripts as add-ins and loading as add-ins from DLL files for which an accompanying .DLL.ADDIN file (which may be empty) also exists. The add-in will then be available in the Tools - Add-ins sub-menu.
This add-in is a C# script that scans a project and saves a text report of the schemas of all tables plus the text for all queries and scripts into a file named for the current date and time, saving the file into the C:\data folder.
Create a file called Save Code.cs containing the script text below and place the file into the ~\shared folder in the Manifold installation hierarchy. Either restart Manifold or choose the Tools - Add-ins - Rescan command. We can Rescan for new add-ins without closing the current project. A new command named Save Code will appear in the Tools - Add-ins sub-menu. Choosing that command will create a text report for the current project within the C:\data folder.
Save the following text into a file called Save Code.cs
// C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using M = Manifold;
class Script
{
static String ReportQuery(M.Database db, String name)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("---- query: " + name);
builder.AppendLine();
builder.AppendLine(db.GetProperty(name, "text"));
builder.AppendLine();
return builder.ToString();
}
static String ReportScript(M.Database db, String name)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("---- script: " + name);
builder.AppendLine();
builder.AppendLine(db.GetProperty(name, "text"));
builder.AppendLine();
return builder.ToString();
}
static String ReportTable(M.Database db, String name)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("---- table: " + name);
builder.AppendLine();
using (M.Table table = db.Search(name))
{
M.Schema schema = table.GetSchema();
foreach (M.Schema.Field field in schema.Fields)
{
builder.AppendFormat("{0} : {1}", field.Name, field.Type);
builder.AppendLine();
}
}
builder.AppendLine();
return builder.ToString();
}
static String Report(M.Database db)
{
// collect component names
List<String> names = new List<String>();
using (M.Table root = db.Search("mfd_root"))
{
using (M.Sequence sequence = root.SearchAll(new String[] { "name" }))
{
while (sequence.Fetch())
names.Add(sequence.GetValues()[0].Data.ToString());
}
}
names.Sort();
// report components
StringBuilder builderTables = new StringBuilder();
StringBuilder builderQueries = new StringBuilder();
StringBuilder builderScripts = new StringBuilder();
foreach (String name in names)
{
String type = db.GetComponentType(name);
if (type == "table")
builderTables.Append(ReportTable(db, name));
else if (type == "query")
builderQueries.Append(ReportQuery(db, name));
else if (type == "script")
builderScripts.Append(ReportScript(db, name));
}
StringBuilder builder = new StringBuilder();
builder.Append(builderTables.ToString());
builder.Append(builderQueries.ToString());
builder.Append(builderScripts.ToString());
return builder.ToString();
}
static M.Context Manifold;
static void Main()
{
DateTime date = DateTime.Now;
String filename = String.Format("c:\\data\\report-{0}-{1}-{2}-{3}-{4}-{5}.txt",
date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
using (M.Database db = Manifold.Application.GetDatabaseRoot())
File.WriteAllText(filename, Report(db));
Manifold.Application.Log("Report saved: " + filename);
Manifold.Application.OpenLog();
}
}
Log Window - The log window tracks attempts to load add-ins from DLL files.
Ignoring DLLs - When Manifold is launched, loading add-ins ignores any DLL files without an accompanying .DLL.ADDIN file. For example, Manifold will not attempt to load an ArcGIS_emulator.dll file if there is not also an ArcGIS_emulator.dll.addin file also present. The .DLL.ADDIN file may be empty. Requiring a .DLL.ADDIN file dramatically reduces the time required to initialize the main menu on startup when there are many DLL modules in Manifold's ~\bin, ~\bin64 and ~\shared folders which do not include add-ins, for example, DLLs for database clients or scripting engines.
Referencing DLLs - To reference a DLL from within an add-in script, use $reference in the initial comments. Example: an add-in called Hello.cs
// C#
//
// $reference: System.Windows.Forms.dll
using WF = System.Windows.Forms;
class Script
{
static Manifold.Context Manifold;
static void Main()
{
WF.MessageBox.Show("Hello from add-in!");
}
}
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.
For information on scripting, see the Manifold API Documentation website.