Chapter 2 Accessing Objects Using Scripts


Global properties

The available global properties can be gathered as follows:

Type Global property Use
Global accessor ActiveModel As BaseObject

ActivePackage As BaseObject

ActiveDiagram As BaseObject
Retrieves the model, package, or diagram that corresponds to the active view
  ActiveSelection As ObjectSet Read-only collection that retrieves the list of selected objects in the active diagram
  ActiveWorkspace As BaseObject Retrieves the Application active Workspace
  MetaModel As BaseObject Retrieves the Application MetaModel
  Models As ObjectSet Read-only collection that lists opened models
  RepositoryConnection As BaseObject Retrieves the current repository connection, which is the object that manages the connection to the repository server and then provides access to documents and objects stored under the repository
Execution mode ValidationMode As Boolean Enables or disables the validation mode (True/False).
  InteractiveMode As long Manages the user interaction by displaying dialog boxes or not using the following constants (im_+Batch, +Dialog or +Abort).
Application UserName As String Retrieves the user login name
  Viewer As Boolean Returns True if the running application is a Viewer version that has limited features
  Version As String Returns the PowerDesigner version
OLE specific ShowMode As Checks or changes the visibility status of the main application window in the following way:

  • It returns True if the application main window is visible and not minimized
  • False otherwise
  Locked As Boolean Can be set to True to ensure that the application continues to run after an OLE client disconnects otherwise the application closes

Example:

'Create a new table in a model
'Get the active model in MyModel variable
Set MyModel = ActiveModel

You can use two types of execution mode when running a script in the editor. A default value can be specified for each mode:

Validation mode

The validation mode is enabled by default (set to True), but you may choose to temporarily disable it by setting it to False.

State Constant Code Use
Enabled (default value) True ValidationMode = True Each time you act over a PowerDesigner object, all internal PowerDesigner methods are invoked to check the validity of your actions. In case of a forbidden action, an error occurs. This mode is very useful for debugging but is necessarily performance consuming
Disabled False ValidationMode = False You use it for performance reasons or because your algorithm temporarily requires an invalid state. However, be aware, that no validation rules such as name uniqueness or link object with missing extremities are applied to your model in this case

Example:

ValidationMode = true

Interactive mode

The interactive mode is Batch by default.

The interactive mode supports the following constants:

Constant Code Description
im_Batch InteractiveMode = im_Batch Never displays dialog boxes and always uses default values. You use it for Automation scripts that require no user interaction
im_Dialog InteractiveMode = im_Dialog Displays information and confirmation dialog boxes that require user interaction for the script to keep running
im_Abort InteractiveMode = im_Abort Never displays dialog boxes and aborts the script instead of using default values each time a dialog is encountered

Option Explicit statement

We recommend to use the Option Explicit statement to declare your variables in order to avoid confusion in code as this option is disabled by default in VBScript. You have to declare a variable before using this option.

Example:

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
' get the current active model
Dim mdl ' the current model
Set mdl = ActiveModel

 


Copyright (C) 2006. Sybase Inc. All rights reserved.