gw_logo_08.gif (1982 bytes)  
Last edit: 2009-05-04 Graham Wideman

ModelRight

Some ModelRight Programming Topics in more Detail

<< ModelRight's Model Explorer and Browsers

Sample ModelRight Scripts  >>

Contents

Accessing MRObject Properties

While the various objects (Tables, Views, Columns etc) in a ModelRight database model are represented by MRObjects, their properties are stored in the Properties collection of each MRObject. Each individual property is actually stored in an MRProperty object, and its value in an MRPropertyValue object.  While this provides great flexibility in the model structure, it's a little puzzling to know how to access it. In fact there are helper methods that make it easier. The following sections provide the basic procedures.

Read a Property

In general, when reading a model property from an MRObject, you usually just want to capture the value into a simple variable. This can be done in one step:

MyVariable = SomeMRObject.Property("SomePropertyName").AsString   ' or AsInteger etc

example:

L = AColumn.Property("Datatype Length").AsInteger

The names of properties that can be used can be found from the Metamodel browser.

Write a Property

Writing to a property is more involved as it requires creating a new MRPropertyValue object with the new value, and then providing that to the parent object:

Set PropValue = Framework.CreatePropertyValue("SomeParentObjectType", "SomePropertyName")
PropValue.FromInteger([number])         ' or FromString etc
Col.SetProperty "SomePropertyName", PropValue

example

PropName = "Datatype Length"
Set PropValue = Framework.CreatePropertyValue("Column", PropName)
PropValue.FromInteger(33)
SomeCol.SetProperty PropName, PropValue

The SetProperty method adds the new MRPropertyValue object to the parent object's Properties collection. If there was already a MRPropertyValue object for the property name, then it will be discarded, and the new one takes its place.

If you have many properties to set, you will probably want to write a subroutine to make this more streamlined.

Special case: SetDataType

Setting the column's Datatype property is slightly different. For this use the MRObject.SetDataType method for the column. This method is provided because the Datatype property is not a simple property (such as a string) but instead holds an object (in fact an MRObject with Type = "Type"), and needs to correspond to an object in the list of types (which you can view in the ModelBrowser Type collection, where you will find the list of strings you can use with the SetDataType method.)

Local vs Inherited Properties

To do.

Transactions

Any changes to the model must be bracketed by Model.BeginTransaction and Model.EndTransaction statements. This gives ModelRight a batch of changes to commit and reconcile at once.

A transaction is used in a couple of ways in ModelRight:

If your code makes a large number of changes, these can be wrapped in a single transaction, or many individual ones, depending on how you might make used of Undo or Alter scripts after the changes.

VB Scripts and the User Interface

Operating only on the user's current selection

Scripts can be written to operate upon only the items which the user has selected on the diagram. To access just these objects, use ScriptFramework.CurrentSelection for the database model objects themselves or ScriptFramework.CurrentDrawableSelection for the Graphics currently selected on the diagram.

Except this doesn't seem to work -- in order to run the script, the script editor has to be selected, and thus CurrentSelection returns the current script.

Prompting or getting input from the user

The usual VB Script popups can be called.

MsgBox: Shows a small modal message box (interrupting the progress of the script, and ModelRight).  Most useful to tell the user something at the end of the script (or on error).

InputBox: Shows a modal dialog into which the user can enter a string which your script can then use.

MsgBox and InputBox are not currently working: GW report GW-1027, email of 2009-04-27 and following.  this doesn't seem to work -- to run the script the script editor has to be selected, and thus the CurrentSelection returns the current script.

 


Document Status
Date (reverse) Who Description
     
2009-04-01 to 05-04 GW Revisions