Scriptable Object Component

The Scriptable Object component, available from the Insert > Component menu, is used to script any Windows object with a scripting or Automation API, including Windows Applications, Mathsoft Controls, or the Mathcad worksheet itself. The component uses the Microsoft ActiveX Scripting specification, allowing you to use standard scripting languages to automate the object. The component additionally provides a mechanism for processing inputs and sending outputs to and from the Mathcad worksheet, and react to updates in variable values just like any other Mathcad definition.

This section is a reference for all methods, properties, and events exposed for scripts in the component. The Scripting Model is fairly abbreviated as the component itself is really just a container for external objects with their own Automation classes. As such, the native methods, properties and events are largely in place to support sending data in and out of the component from the worksheet. Classes for the Mathsoft Controls are also included here, as these properties, methods and events may be useful for triggering how a scripted object appears and is activated by the user.

Finally, all scripted components can be exported, and registered for use on other Mathcad-equipped systems so they appear on Mathcad's Insert > Component menu. This allows you to make customized components and distribute them to others in your company or to clients as part of a Mathcad solution.

Inputs and Outputs

The Scriptable Object wizard will ask you to assign the number of input and output placeholders. The overall number can be modified after creation by right-clicking on the object and choosing Add/Delete Input Variable or Output Variable. These values can then be addressed as Inputs(n).Value or Outputs(n).Value, and are members of DataValue Collections. Indexing of input and output variables starts at 0. Inputs and outputs may be of any Mathcad supported data type including numbers, arrays, and strings.

Note that you can also get and set values in the worksheet by using Mathcad's Automation commands in the script, GetValue and SetValue. However, you may need to explicitly include a Recalculate method for the control or the worksheet, since this activity is automatically handled by the Input and Output variables on the control, but not by Automation commands. You will also need to include the variable name you are getting as an input, to preserve calculation order. Further, values that you get through Automation must be defined only once in the worksheet.

Recalculating from a Scripted Object

An OCX wishing to force a recalculation in Mathcad should fire an OLE event with DISPID 516. Mathcad will recalculate the region and its dependents immediately if AutoCalc is on, or in response to F9 otherwise. This is what the Mathsoft controls do when the script's Click handler calls a Recalculate method.

Examples

These examples are intended to show the syntactic conventions and how they apply to various object methods and properties, rather than production quality scripts. Examples use VBScript style syntax unless otherwise noted.