logo WinWrap®

Easily Script Your Application's Object Model

WinWrap® Basic is an embedded macro language component available for .NET and COM 32/64 bit Windows applications. The WinWrap® Basic Component is an alternative to Visual Basic for Applications (VBA), ActiveX (e.g. VBScript, JScript, PerlScript, Rexx-based WSH engines and others), and VSTA for this purpose. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

Enable Scripting of Your Application Object Model

  • Elevate scriptable members and types to the WWB.NET language
  • Edit scripts with auto completion for your object model
  • Run, debug and pause scripts controlling your application
  • UI active while script execution occurs


Scriptable Application

Debugger

Breakpoints

Non-Blocking

Scriptable Architecture

Auto Completion

Parameter Info

Access .NET Framework

Script Your Application's Object Model

Use your application's own object model and the WinWrap® Basic scripting control to create a scriptable application.

THIS EXAMPLE ILLUSTRATES HOW!!! See this ScriptableObjectModel example at GitHub https://github.com/WinWrap/HowtoExamples. You can also download the WinWrap HowtoExamples zipfile. To run this example in Visual Studio, open ScriptableObjectModel.sln.

Script Your Application's Object Model

Define a shared interface used by both the host application and the language extensions. The WinWrap® Basic autocompletion capability provides builtin documentation for your users when they write scripts. This is builtin documentation for the scripting language, for your applications language extensions, and for Microsoft .NET classes and objects. End-users need autocompletion and its builtin documentation.

Debug the Scripts in Your Application

Ship a complete environment for creating and debugging end-user scripts. End-users can debug their WinWrap® Basic scripts. Macro editing, execution and debugging are supported through the IDE embedded in the host application.

Click on the pause button to pause execution.

Debug a Script

Set a Breakpoint and Run the Script Until the Breakpoint is Reached

Set a Breakpoint

Other debugging features:

  • Set break points, continue from break points
  • Inspect script variables
  • Watch script variables

The Application User Interface is Not Blocked During Script Execution!

WinWrap® Basic running scripts do not block the calling application. The WinWrap® Basic scripting control process Windows message 10 times per second. This allows the scriptable application to run scripts in the same thread as the UI.

Your Application UI is not Blocked

The sample application draws the red circles while the script is executing.

public partial class Form1 : Form, IDrawing { . . . #region Draw Ellipses private Stack<int> _iter; // pop element for each ellipse private int _lim = 20; // # of ellipses to draw // initialize ellipses count and start timer private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { _iter = new Stack<int>(Enumerable.Range(1, _lim).Reverse()); timer1.Enabled = true; } // draw ellipse and pop stack private void timer1_Tick(object sender, EventArgs e) { int w = pictureBox1.Width; int h = pictureBox1.Height; int i = _iter.Pop(); DrawEllipse(0, 0, w * i / _lim - 1, h * i / _lim - 1); if (_iter.Count == 0) timer1.Enabled = false; } // draw an ellipse into the drawing area public void DrawEllipse(int x1, int y1, int x2, int y2) { Rectangle rect = new Rectangle(x1, y1, x2, y2); using (Graphics g = Graphics.FromImage(_drawArea)) { g.DrawEllipse(Pens.Red, rect); } pictureBox1.Image = _drawArea; } #endregion . . . } }

Auto Completion for the Application's Scriptable Object Model

This application has the WinWrap® Basic IDE control beside a PictureBox control. EraseLines and DrawLine methods draw onto the PictureBox from the script. The scriptable application classes, methods, and events have full script edit autocompletion enabled in the WinWrap® Basic IDE editor.

Available members are also shown.

Auto Completion for Your App's Object Model

Method Parameters Are Shown During Editing

The script below show how application methods like "DrawLine(x1, y1, x2, y2)" are incorporated seamlessly into the WinWrap® Basic scripting language. This gives your application automatic script editing documentation for your application's scriptable object model.

Editor Shows Method Parameters

Microsoft Foundation Classes Are Available

End-users can access any of thousands of .NET Framework classes. In this sample script System.Math's static field PI is used.

Access the Microsoft Foundation .NET Framework
  • Access to the Microsoft .NET Framework
  • Access to 3rd party .NET code assemblies

Add Scripting (of Your Application Model) to Your Application

The application uses the AddScriptableObjectModel method to add the "scriptable" portions of the application's object model to the WWB.NET language.

Application Model's Object accessible with AddScriptableObjectModel
  1. The application uses the AddScriptableObjectModel method to add the "scriptable" portions of the application's object model to the WWB.NET language.
  2. The IDrawing interface (application specific) allows the scripting implementation to access the application's drawing area.
  3. The script uses WWB.NET with the application's object model to control the sample application.

Add Scriptable Subset to WinWrap® Basic

During the Form Load event connect the ScriptingLanguage to the IDrawing instance and establish the scriptable object model used by WinWrap® Basic.

private void Form1_Load(object sender, EventArgs e) { // connect the scripting language to the IDrawing instance ScriptingLanguage.SetDrawing(this); // establish the scriptable object model used by WinWrap Basic basicIdeCtl1.AddScriptableObjectModel(typeof(ScriptingLanguage)); . . . }

Declare a Scriptable Subset of Classes, Methods, Properties and Events

AddScriptableObjectModel adds a static scriptable class's methods, and events directly to the WinWrap® Basic scripting language. Types in the static class's name space are also added. Use the [Scriptable] attribute on a type or member to enable script access.

[Scriptable] public static class ScriptingLanguage { internal static IDrawing Drawing { get; private set; } // connect the scripting language to the IDrawing instance public static void SetDrawing(IDrawing drawing) { Drawing = drawing; } [Scriptable] public static int PictureWidth { get { return Drawing.PictureWidth; } } [Scriptable] public static int PictureHeight { get { return Drawing.PictureHeight; } } [Scriptable] public static void DrawLine(int x1, int y1, int x2, int y2) { Drawing.DrawLine(x1, y1, x2, y2); } [Scriptable] public static void EraseLines() { Drawing.EraseLines(); } }

The scriptable members may need to access to non-scriptable portions of the host application. This sample uses the IDrawing interface for that purpose. Your scriptable application will use an interface of your own design.

// interface to access non-scriptable portions of the host application public interface IDrawing { int PictureWidth { get; } int PictureHeight { get; } void DrawLine(int x1, int y1, int x2, int y2); void EraseLines(); }

In this sample application, it's Form1 that implements the members of the IDrawing interface which are used by the members of the ScriptingLanguage class.

public partial class Form1 : Form, IDrawing { . . . #region IDrawing private Bitmap _drawArea; // get the width of the drawing area public int PictureWidth { get { return pictureBox1.Width; } } // get the height of the drawing area public int PictureHeight { get { return pictureBox1.Height; } } // draw a line into the drawing area public void DrawLine(int x1, int y1, int x2, int y2) { using (Graphics g = Graphics.FromImage(_drawArea)) { g.DrawLine( new Pen(Color.Blue, 2f), new Point(x1, y1), new Point(x2, y2)); } pictureBox1.Image = _drawArea; } // erase all the lines from the drawing area public void EraseLines() { _drawArea = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height); pictureBox1.Image = _drawArea; } #endregion }

Conclusion

WinWrap® Basic provides a comprehensive solution to adding scripting to your application. You and your customer can write script code that uses your application's objects. Scripts are validated for syntactic correctness. Scripts can be debugged. The application UI remains active during script execution. Scripts have full access to the .NET assemblies including the Microsoft .NET Foundation Classes.

This is a great way to script. This is a great way to add scripting to your application. Edit scripts with autocompletion. Debug scripts. Use .NET Foundation Classes. Run scripts while not blocking your application's UI.

Copyright Polar Engineering, Inc.