Chapter 9 Accessing objects using VBScript


Global properties

The following global properties are available:

Global properties Use
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
Models As ObjectSet Read-only collection that lists opened models
MetaModel As BaseObject Retrieves the Application MetaModel
ActiveWorkspace As BaseObject Retrieves the Application active Workspace
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).
UserName As String Retrieves the user login name
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
ScriptInputParameters As String Read-only property optionally filled in by the script caller
ScriptInputArray As String Read-only property optionally filled in by the script caller
ScriptResult As String Writes the property to be used to return a result from a script execution

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

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.

Example:

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

 


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