News from the MBS Xojo Plugins Version 26.1
In this article I want to introduce you the new functionalities from the MBS Xojo Plugins in version 26.1.
Llama
Everyone is talking about AI, and we're working to give you the most out of this technology. We've added a new topic called Llama to the Plugins section. This component provides features that let you use a local LLM on your computer. This allows you to download a model, use it locally, and query it in a chat. You can learn how this works in detail in our blog post Use Llama.cpp in Xojo
JSON to TOON
We have added a new method, ToToon, to the JSONMBS class. It converts JSON to TOON. TOON stands for Token-Oriented Object Notation and is primarily used in the context of communication with AI. A conversion from JSON to TOON might look like this:
Var j As JSONMBS = JSONMBS.NewObjectNode
j.Value("hello") = "world"
j.Value("test") = 123
j.value("values") = Array(1,2,3)
Var s As String = j.ToToon
For more information about TOON and the new method, see the blog post TOON: A Token-Efficient Alternative to JSON - Now in MBS Plugin for Xojo
OCR
The new TessResultRendererMBS class provides an interface for rendering Tesseract results into a document, such as text, HOCR, or PDF. Using the ProcessPages method from the TessEngineMBS class, you can use text recognition to extract text from one or, in the case of a TIFF file, multiple pages that are stored as images. Among other things, you can specify a renderer of type TessResultRendererMBS in the parameters. This allows you, for example, to render the result into a PDF document. Your code might look like this:
var ocr as new TessEngineMBS
// initialize with right paths
If Not ocr.Initialize(tessdataPath, Languages) Then
MsgBox "failed to initialize"
Quit
End If
// pass image file
ocr.SetImageFile(imagefile)
// now write PDF file
Var p As FolderItem = SpecialFolder.Desktop.Child("test") // no extension!
Var r As TessResultRendererMBS = TessResultRendererMBS.CreatePDFRenderer(p.NativePath)
If r.BeginDocument("Hello") Then
Call ocr.ProcessPages(ImageFile.NativePath, "", 0, r)
call r.EndDocument
End If
Phidget
There's also news in the Phidget topic. We've added two new events: WakeUp and WillSleep, which allow you to monitor transitions between activity states. We've also added a new class, PhidgetCurrentOutputMBS, for current output. And with the PhidgetLEDArrayMBS class, you can now work with LED arrays. Here you'll find methods and properties that let you set individual LEDs or run LED animations through the LED array. The PhidgetLEDArrayColorMBS class helps you specify the colors of the individual LEDs. In the properties of this function, you can specify colors using RGB and set the intensity.
Digest
For encryption, we've also added a new shared method for compatibility reasons, which allows us to encode text using MD4. The shared method MD4 from the DigestMBS class returns the MD4 cipher. We can then use this for encoding.
Var d As DigestMBS = DigestMBS.MD4 d.Process "Hello World" Var result As String = d.FinalText MsgBox result
Another new feature is the XOFLen property, which determines the digest length for extendable output functions.
DynaPDF
There's big news at DynaPDF, because DynaForms released DynaPDF 5.0, their newest version of the DynaPDF library. With the new release DynaForms changes the prices and we follow them. The new prices for Lite, Pro and Enterprise licenses are lower. This makes the entry more affordable. Starter costs more and is now half of the Lite price. Maintenance updates are 15% of the product prices. You can learn more about the new features awaiting you in DynaPDF 5.0 in the blog post DynaPDF 5 Introduction
We have also added new methods to the DynaPDFPointMBS class. An object of this class represents a point within a PDF. Previously, it was only possible to create such an object by specifying the X and Y values. Now, you can use an existing point in the constructor to create a new object. This point can, for example, be used as a reference point and then modified by adjusting the X or Y values.
Var p As New DynaPDFPointMBS(3, 4) Var c As New DynaPDFPointMBS(p) // modify first one p.X = 5
We've also added operations that allow us to work with points; for example, we can use Operator_Add to add two points together to create a new point. The Operator_Compare method allows us to compare two points. Similarly, there's the Operator_Subtract method, which subtracts one point from another. There is also the Operator_Multiply method, which can be used to multiply either a value by a point or another point.
Var p As New DynaPDFPointMBS(3, 4) Var o As New DynaPDFPointMBS(2, 3) Var r As DynaPDFPointMBS = p * o // show values MessageBox Str(r.X)+"/"+Str(r.Y) // shows 6/12 p = p * 2 // show values MessageBox Str(p.X)+"/"+Str(p.Y) // shows 6/8
We also have the new SqDist property, which specifies the distance from a point to the origin of the coordinate system.
In the DynaPDFRectMBS class, which describes a rectangle in a DynaPDF environment, we have added a new constructor that allows us to create a new object of this class using an existing DynaPDFRectMBS. We can then, for example, move the rectangle using the new methods MoveX, MoveY, or Translate, and scale it by a specific value using the Scale method. Additionally, we have new methods that allow us to check whether two rectangles intersect (Intersect) or whether one rectangle is completely contained within the other (IsInside). We can use Operator_Compare to compare two rectangles with each other or use Widen to enlarge one rectangle so that it completely contains the other rectangle.
Here, too, there are corresponding new properties. You can read the height of the rectangle using Height. For the width, we've had the Width property in the class for some time, and you can also determine the absolute values of the height and width using HeightAbs and WidthAbs. The difference between the absolute values and the simple measurements can be seen when the second point specified to define the rectangle is less than the first.
Var p As New DynaPDFRectMBS(3,4,2,1) MessageBox p.Width.ToString+"/"+p.Height.ToString+EndOfLine+_ p.WidthAbs.ToString+“/"+p.HeightAbs.ToString
Graphics Magick
Using the new Profiles method from the GMImageMBS and GM16ImageMBS classes, you can retrieve a list of available profiles for an image. An example of such a list might look as follows:
Var item As FolderItem = SpecialFolder.Desktop.Child("test.jpg")
Var p As New GMImageMBS(item)
Var Str() As String = p.Profiles
Var c As Integer = Str.Count
Var i As Integer =0
Var t as String=""
Do Until i >= c
t=t+Chr(13)+Str(i)
i=i+1
Loop
MessageBox t
XL
There's also news in the XL area, which allows you to work with Excel spreadsheets using Xojo. The XLBookMBS class now includes a new method called Clear. This clears the entire workbook. Using the ErrorCode property, you can retrieve the last error code to better understand and resolve errors. With LoadInfo, you load only the metadata for an Excel document. You can specify the document in the parameters as a FolderItem, or you can specify the path as a string. After calling this method, you can then use SheetCount() and SheetName(index).
Var f As New FolderItem("/Users/cs/Desktop/test.xlsx", folderitem.PathModes.Native)
Var b As New XLBookMBS(True)
If b.LoadInfo(f) Then
var names() as string
Var c As Integer = b.SheetCount
For i As Integer = 0 To c-1
names.add b.SheetName(i)
Next
MessageBox Join(names, EndOfLine)
End If
If you want to load the metadata of an Excel file into memory, feel free to use the LoadInfoRaw method.
We've also added new features for conditional formatting. The ConditionalFormatSize property returns the number of conditional formats in the workbook. Using the ConditionalFormat method, we can retrieve a conditional format by specifying a specific index. With ConditionalFormats, we get an array containing all conditional formats from the workbook.
There are also new features regarding conditional formatting in the XLSheetMBS class, whose objects describe individual sheets in a workbook.
To determine the number of conditional formatting rules in this worksheet, we use the ConditionalFormattingSize property. To retrieve such a rule from a sheet in an xlsx document, we use the ConditionalFormatting method, passing it the appropriate index. In the same way, we can also remove this rule using RemoveConditionalFormatting. If you want to retrieve all formatting rules for a sheet, the ConditionalFormatting method returns them in an array.
If you want to find out which tables are in your sheet, use the Tables method to retrieve the tables in an XLTableMBS array. If you want to query all form controls on a sheet, FormControls will help you by returning an array of XLFormControlMBS objects.
Quality of Service class
The new global method SetQOSClassMBS allows you to set the Quality of Service class for the current thread. This tells the scheduler how to prioritize the thread and whether to run it on a faster or more efficient CPU core. You can choose from the following values:
| Name | Value | Description |
|---|---|---|
| QOS_CLASS_USER_INTERACTIVE | 5 | The thread handles user input. |
| QOS_CLASS_USER_INITIATED | 4 | The user requested this action. |
| QOS_CLASS_DEFAULT | 3 | Default |
| QOS_CLASS_UTILITY | 2 | Utility thread running with reduced priority, e.g. menubar utility app. |
| QOS_CLASS_BACKGROUND | 1 | Background thread with reduced priority, e.g. backup. |
| QOS_CLASS_UNSPECIFIED | 0 | Unknown level. |
Of course, we also have the corresponding global method GetQOSClassMBS, which queries the value for the current thread. For more information, see our article Moving background threads to efficient cores.
Arrays
We have added the new global method GetArrayDimensionMBS, which allows us to determine the dimension of an array. Here is an example:
Var test3(7,7,7) As Integer Var t As Integer = GetArrayDimensionMBS(test3) MessageBox Str(t)+" dimensions" // shows 3
New functionalities for Mac
The MBS Xojo Plugins in version 26.1 offers some more new features for Mac users.
NSWorkspace
We have added new methods to the NSWorkspaceMBS class to help you process files. The ApplicationsToOpenFile method returns an array containing all the paths to the applications that can open a specific file, which you specify in the parameters. For example, the screenshot shows a list of paths to applications that can open a JPG image.
The situation is similar with the methods ApplicationsToOpenURL for URLs and ApplicationsWithBundleIdentifier for applications that can open the specified bundle identifier. In contrast, ApplicationToOpenFile, ApplicationToOpenURL, and ApplicationWithBundleIdentifier each return the path to the program that runs by default when we want to open such a file.
With openApplicationFile and openApplicationURL, we can open one of the corresponding programs that we have received as a path. With openFile and openURL, you can then open your file or URL - either with the default program or with the program of your choice. You must then specify this as an additional FolderItem in the parameters. To go along with this, you also have a new class, NSWorkspaceOpenConfigurationMBS, where you can specify properties for configuring the opening of URLs and files. Once the opening is complete, the openCompleted event is triggered.
We've also added a few more useful methods to NSWorkspaceMBS. With duplicateFiles, you can duplicate multiple files at once. The duplication process runs asynchronously, which makes the duplicateCompleted` event very useful. If you want to retrieve the icon for a specific content type, iconForContentType can help you with that. The recycleFiles method moves the specified URLs to the trash in the same way as the Finder. To go with this, we've also included the recycleCompleted event.
CTFontDescriptorMBS conversion
In this release, we've added methods that enable conversion from an NSFontDescriptorMBS object to a CTFontDescriptorMBS object and vice versa. This can be very useful in certain situations. The CTFontDescription method from the NSFontDescriptorMBS class converts an NSFontDescriptorMBS into a CTFontDescriptorMBS object. The shared method FontDescriptorWithCTFontDescriptor from the same class converts a CTFontDescriptorMBS into an NSFontDescriptorMBS object.
Vision
In the Vision section, we have added the new automaticallyDetectsLanguage property from the VNRecognizeTextRequestMBS class. This property allows you to specify whether Vision should automatically detect the language during the detection process. Language detection will attempt to automatically identify the script/language during detection and use the appropriate model for recognition and language correction. This can be particularly helpful if the nature of the content is unknown; with this flag set, it will, for example, determine whether the text is in Latin or Chinese, so you don't have to select the language model in the first instance. However, since language correction cannot always guarantee correct detection, it is advisable to specify the languages yourself if you have domain knowledge of what language to expect.
New functionalities for Windows
Last but not least we offer new features for Windows users
Dialog
The TaskDialogMBS class now includes a new property called TitleIcon. You can use TitleIcon to display a custom icon in the title bar. Specify this image as a Picture in the parameter.
Var logo as Picture = LogoMBS (500) Var td as new TaskDialogMBS td.CommonButtons = td.kCommonButtonOK td.Content = "Hello World" td.AllowDialogCancellation = true td.TitleIcon = logo td.IconPicture = logo call td.ShowDialog
We hope you will also find some interesting new features. We wish you a lot of fun with MBS Xojo Plugins version 26.1. If you have any Ideas for new cool features, need a license or have any questions, please contact us.