Samples for Message Dialogs:
ShowMessageDialog
System.ShowMessageDialog(1004,'WarningDialog','Please select shapes on your Workspace before running the macro.',2,4);
Dialog type index
0 - warning
1 - error
2 - info
3 - confirm
4 - no icon
Dialog buttons index
0 - no button
1 - yes
2 - no
3 - yes/no
4 - ok
5 - yes/ok
6 - no/ok
7 - yes/no/ok
8 - cancel
9 - yes/cancel
10 - no/cancel
11 - yes/no/cancel….
ShowMessageDialogScript
This way you can create dialog with hyperlinks at the bottom.
var DlgParams = System.CreateObject('DialogParams');
DlgParams.Caption = 'Add Entities Info';// Name appears in Settings | Options in section Dialog Boxes.
DlgParams.DialogIndex = 202; // Unique number, must be above 200
DlgParams.Msg = 'This macro allows you to quickly add entities to your model. Specify one entity caption per line. ';
DlgParams.Msg += 'Spaces in entity captions can be converted to entity names as underscore characters. ';
DlgParams.Msg += 'For more infomation click the Help link at bottom. Do you wish to continue?';
DlgParams.Buttons = 3;
DlgParams.DlgType = 2;
DlgParams.HyperLink = 'http://www.casestudio.com/help/ProductivityPack.aspx';
DlgParams.HyperLinkCaption = 'Help';
DlgParams.ScriptName = 'AddEntitiesMacro';
if(System.ShowMessageDialogScript(DlgParams) != 6)
{
return;
}
You can write scripts inToad Data Modeler , save the scripts to packages, distribute the packages etc. - This will be explained later. Now you will see how to work with Scripting Window that allows you to run scripts at once, without the necessity to have them stored in packages.
Click Expert Mode | Scripting Window to open it. (Of course, Expert Mode has to be turned on.)
The following dialog appears. If you don't see the upper part of the Scripting Window, select View | Show Registered Objects.
On the left, you can see available models. Use the arrows to select model you want to work with. In our example, we will execute script for Videorental model (for Oracle 10g).
In the Name in Script column, you can define name that will be used in the script. Our OrigModel value will represent the selected Videorental model.
Write script to the main() function.
Code:
function main(){
var i, e;
var Ent;
var EntListConfirmed = new Array();
var EntListNotConfirmed = new Array();
// iterate through entities and check the value of ConfirmedByCustomer property
for (i=0; i<OrigModel.Entities.Count; i++)
{
Ent = OrigModel.Entities.GetObject(i);
if(Ent.ConfirmedByCustomer == true)
EntListConfirmed[EntListConfirmed.length] = Ent.Name; // add to list of confirmed entities
else
EntListNotConfirmed[EntListNotConfirmed.length] = Ent.Name; // add to list of not confirmed entities
}
// write list of confirmed entities to Log.
Log.Information ("--------------------------------------");
Log.Information ("List of entities confirmed by customer");
Log.Information ("--------------------------------------");
for (e=0; e<EntListConfirmed.length; e++)
{
Log.Information(EntListConfirmed[e]);
}
Log.Information ("# Number of confirmed entities: "+EntListConfirmed.length.toString());
// write list of NOT confirmed entities to Log.
Log.Information ("--------------------------------------");
Log.Information ("List of entities NOT confirmed by customer");
Log.Information ("--------------------------------------");
for (e=0; e<EntListNotConfirmed.length; e++)
{
Log.Information(EntListNotConfirmed[e]);
}
Log.Information ("# Number of NOT confirmed entities: "+EntListNotConfirmed.length.toString());
}
Where to find information about objects and their properties and methods?
Explanation of Items in Bold:
OrigModel.Entities.Count
- OrigModel - represents object assigned in the upper part of the Scripting Window (Videorental object renamed to OrigModel).
- Entities - we work with Physical Entity Relationship model, therefore we need to search for PER object. Model is for Oracle 10g, let's find the PERModelOR10 object in the Reference.
- Count - represents a feature that is available for all List objects. On the screenshot above, you can see that the Entities datatype is a List. Let's click the List link and see details of the List class.
OrigModel.Entities.GetObject(i)
- GetObject - belongs to the List class.
Ent.ConfirmedByCustomer
- Ent - is a variable that holds assigned Entity objects (assigned earlier using the OrigModel.Entities.GetObject(i)function).
- ConfirmedByCustomer - property of PEREntityOR10 object, added to Metamodel of the CustomerFeedback package.
Ent.Name
- Ent - is a variable that holds assigned Entity objects (assigned earlier using the OrigModel.Entities.GetObject(i)function).
- Name - property of PEREntityOR10 object. We still work with PER model and now we need to find property of Entity in Oracle 10g model. Let's see properties of the PEREntityOR10 object.
.length and .toString()
- both are standard JavaScript items.
Executing the Script
Click Execute Script. Result will be displayed in the Message Explorer and Log area.
For more information, see Create Script.
You can create new files or folders using simple javascript code.
function CreateFolder(folder)
{
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CreateFolder (folder);
}
function CopyFolder(sourceFolder, destinationFolder, overwrite)
{
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFolder (sourceFolder, destinationFolder, overwrite);
}
function CopyFile(sourceFile, destinationFile)
{
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile (sourceFile, destinationFile);
}
You know how to execute scripts from the Scripting Window. If you want to store the script and call it from another form in the application, for example, do the following:
Create a new script WriteFeedbackToLog. See the "Adding Events" topic to find out how to create new scripts.
Write there function WriteFeedback.
Code
function WriteFeedback ()
{
var Log = System.CreateObject('Log');
var Application = System.GetInterface('Application');
var OrigModel;
OrigModel = Application.Models.GetObjectByID(Model.ID);
....
....
}
Explanation
The WriteFeedback function is almost identical to the Main function we were executing from the Scripting Window.
The only difference is in the definition of OrigModel object. In the Scripting Window, we could select Videorental and define the OrigName name.
However, now we have no means to select the object visually (and we do not need it, the function will be executed for active model). Therefore we need to define the OrigModel object via Application.Models.GetObjectByID method, with parameter Model.ID.
This way we can get the currently active model.
We also need to register object Log. (It is not necessary to register Log in the Scripting Window. Log is registered in the Scripting Window automatically.)
The rest of the script is identical.
For more information, see Call Existing Script from Model Properties Form.