Skip to Content

I found the following in the PD Documentation and it is so essential that i need to share it !

Differences between scripting and 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 program highlights what differentiates OLE Automation from VBScript.

VBScript program

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:

  • Get the current active model using the ActiveModel global function

  • Check the existence of an active model and if the active model is an OOM

  • Count the number of classes in the active OOM and display a message in the Output window

  • Create a new OOM and display its name in the Output window

'* 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

OLE Automation program

To do the same with OLE Automation program, you should modify it as follows:

  • Add the definition of the PowerDesigner application

  • Call the CreateObject function to create an instance of the PowerDesigner Application object

  • Prefix all the global functions (ActiveModel, Output, CreateModel) by the PowerDesigner Application object

   

  • Release the PowerDesigner Application object

     
  • Use specific types for the variables “model” and “model2”

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply