Welcome to the Legato Developers Corner! This is a weekly blog designed to help developers use Legato to customize GoFiler to their specific needs. Legato is a structured, comprehensive programming interface that can wrap around GoFiler and interact with numerous document sources and destinations, including the internet, cloud storage systems, and databases. Legato can automate tasks, like different aspects of a document’s edit cycle, as well as offer enhanced document control, data loading procedures and validation, and project process control. With Legato, you as a programmer have the ability to adjust, customize, and interface GoFiler with other applications and programming languages, access the EDGAR System, and the capacity to adapt GoFiler to function exactly how you want is virtually endless.
Each week, the Legato Developers Team will explore Legato and its applications. This can mean enhancing GoFiler itself or creating scripts that perform tasks outside the scope of GoFiler and EDGAR. We will present a script, explore its components, and examine how it can be used. These scripts will include such things as:
1. | | Creating custom functions |
2. | | Creating custom dialogs and menu items |
3. | | Integrating with external databases |
4. | | Using Legato to parse EDGAR information |
5. | | Controlling the appearance of GoFiler |
6. | | Enhancing document control and customizing user processes |
This is an open blog, and we welcome input from the community concerning what topics and types of scripts should be explored and discussed. The Legato Reference Manual contains detailed information on both beginner and advanced topics and is available at www.novaworkssoftware.com/legato. For more information and discussion, feel free to join the Legato Script Developers Group on LinkedIn at https://www.linkedin.com/groups/8187707. Finally, the Legato Developers Team can be reached by email at legato@novaworkssoftware.com.
Creating a Legato Script
Legato is built into GoFiler Complete, so creating a script is simple and easy. Use the New command; pleasenote that currently the option to make a new Legato script is only available from the New dialog. When you create a new script, the IDE will automatically open along with your new blank document. The IDE contains many scripting options and tools via the Script Ribbon, and the Code View edit window has color coding to distinguish between various items within the script. Additionally, GoFiler provides integrated scripting help, including tooltips for function parameters and easy access to the Legato SDK. Legato scripts are saved with either a .ls or .ms extension.
Let’s examine a simple Legato script to resize an image:
// GoFiler Legato Script - Resize Image
// ------------------------------------------
//
// Rev 10/2/2014
//
// (c) 2014 Novaworks, LLC -- All rights reserved.
//
//
// Notes:
// - None.
handle hImage; // handle for image
int ec; // error code
// Load an image
hImage = ImageLoad("C:\\Users\\jsmith\\Pictures\\mycat.bmp");
// Check for errors
if (hImage == NULL_HANDLE) {
ec = GetLastError();
MessageBox("Image load failed! Error code: %d", ec);
exit;
}
// Resize the image
ImageResizePercent(hImage, 50);
// Export the image
ec = ImageExportJPEG(hImage, "C:\\Users\\jsmith\\Pictures\\mycat.jpg", 75);
// Check for errors
if (ec == ERROR_NONE) {
MessageBox("Image conversion successful!");
}
else {
MessageBox("Image conversion failed! Error code: %d", ec);
}
// Clean up
CloseHandle(hImage);
This script loads an image, resizes it, and exports it to a different format. You’ll immediately notice that Legato, like many other languages such as C++, Java, and PHP, has statements that end with semi-colons. Statements can encompass multiple lines and any amount of white space. Curly braces enclose blocks of statements in common programming constructs, such as loops and conditional expressions. Comments in Legato can either be single line (marked with “//”) or block (marked with “/*” to start the block and “*/” to close it).
As with structured languages like C++ and Java, Legato variables have specific types (integers, characters, floating point numbers, and so forth) and these variables must be declared before use. In the above script, ec is defined as an int and hImage is defined as a handle. Legato also has a library of functions that can perform a wide variety of tasks and return information (such as error codes). We see a few of them above. We first use the LoadImage function, which takes a path to an image file and creates a handle (hImage) to the image which can then be used in subsequent functions. Following this, the ImageResizePercent function is called to perform the resizing using the supplied image handle and a resizing parameter. Once that is complete, we then employ the ImageExportJPEG function to convert the image from a bitmap to a JPEG and store it with the supplied path and filename. If this function were to return an error, the MessageBox function is called to display the error (a message and the return code). If not, the MessageBox function simply alerts the user the process completed successfully. Finally, we use the CloseHandle function to release the handle we used.
This script is simple but can perform a powerful task. You can see how running a few lines of code like this in a loop could automate resizing and exporting an entire directory of images, which would be a laborious process by hand. This is but one of the many processes Legato can automate and customize. In addition to the SDK’s large library of functions, you can certainly create your own as well. Legato is robust, versatile, and capable of enhancing GoFiler to streamline your document preparation process.
Again, welcome to the Legato Developers Corner! We hope to present a variety of scripts, tools, and examples of how to use Legato to tailor GoFiler to be exactly what you need.
Additional Resources
Novaworks’ Legato Resources
Legato Script Developers LinkedIn Group
Primer: An Introduction to Legato