Chapter 9 Communicating With PowerDesigner Using OLE Automation
VBScript programs and OLE Automation programs are very similar. You can easily create VB or VBA programs, if you know how to use VBScript.
However, some differences remain. The following example of program highlights what differentiate OLE Automation from VBScript.
The following VBScript program allows you to count the number of classes defined in an OOM and display that number in PowerDesigner Output window, then create a new OOM and display its name in the same Output window.
To do so, the following steps are necessary:
'* Purpose: This script displays the number of classes defined in an OOM in the output window.
Option Explicit
' Main function
' Get the current active model
Dim model
Set model = ActiveModel
If model Is Nothing Then
MsgBox "There is no current model."
ElsIf Not Model.IsKindOf(PdOOM.cls_Model) Then
MsgBox "The current model is not an OOM model."
Else
' Display the number of classes
Dim nbClass
nbClass = model.Classes.Count
Output "The model '" + model.Name + "' contains " + CStr(nbClass) + " classes."
' Create a new OOM
Dim model2
set model2 = CreateModel(PdOOM.cls_Model)
If Not model2 Is Nothing Then
' Copy the author name
model2.author = model.author
' Display a message in the output window
Output "Successfully created the model '" + model2.Name + "'."
Else
MsgBox "Cannot create an OOM."
End If
End If
To do the same with OLE Automation program, you should modify it as follows:
'* Purpose: This script displays the number of classes defined in an OOM in the output window.
Option Explicit
' Main function
Sub VBTest()
' Defined the PowerDesigner Application object
Dim PD As PdCommon.Application
' Get the PowerDesigner Application object
Set PD = CreateObject("PowerDesigner.Application")
' Get the current active model
Dim model As PdCommon.BaseModel
Set model = PD.ActiveModel
If model Is Nothing Then
MsgBox "There is no current model."
ElsIf Not model.IsKindOf(PdOOM.cls_Model) Then
MsgBox "The current model is not an OOM model."
Else
' Display the number of classes
Dim nbClass
nbClass = Model.Classes.Count
PD.Output "The model '" + model.Name + "' contains " + CStr(nbClass) + " classes."
' Create a new OOM
Dim model2 As PdOOM.Class
Set model2 = PD.CreateModel(PdOOM.cls_Model)
If Not model2 Is Nothing Then
' Copy the author name
model2.Author = Model.Author
' Display a message in the output window
PD.Output "Successfully created the model '" + model2.Name + "'."
Else
MsgBox "Cannot create an OOM."
End If
End If
' Release the PowerDesigner Application object
Set PD = Nothing
End Sub
To use OLE Automation to communicate with PowerDesigner, you need to:
| Copyright (C) 2006. Sybase Inc. All rights reserved. |
| |