Chapter 9 Accessing objects using VBScript


Manipulating the Workspace using VBScript

PowerDesigner lets you access the workspace feature via VBScript using the ActiveWorkspace As BaseObject global property.

It allows you to retrieve the application current workspace

The Workspace object corresponds to the workspace root in the Browser.

The main actions you can perform with the Workspace are the following:

To load a workspace:

Use the following Description
Load (ByVal filename As String = "") As Boolean Loads the workspace from the given location

To save a workspace:

Use the following Description
Save (ByVal filename As String = "") As Boolean Saves the workspace at the given location

To close a workspace:

Use the following Description
Close () Closes the active workspace

You can also manipulate the contents of a workspace using the following items:

You can use the AddDocument(ByVal filename As String, ByVal position As Long = -1) As BaseObject method on the WorkspaceFolder to add documents to the workspace.

Example of a workspace manipulation:

Option Explicit
' Close existing workspace and save it to Temp
Dim workspace, curentFolder
Set workspace = ActiveWorkspace
workspace.Load "%_EXAMPLES%\mywsp.sws"
Output "Saving current workspace to ""Example directory : "+EvaluateNamedPath("%_EXAMPLES%\temp.sws")
workspace.Save "%_EXAMPLES%\Temp.SWS"
workspace.Close
workspace.Name = "VBS WSP"
workspace.FileName = "VBSWSP.SWS"
workspace.Load "%_EXAMPLES%\Temp.SWS"
dim Item, subitem
for each Item in workspace.children
   If item.IsKindOf(PdWsp.cls_WorkspaceFolder) Then 
      ShowFolder (item)
      renameFolder item,"FolderToRename", "RenamedFolder"   
      deleteFolder item,"FolderToDelete"
      curentFolder = item
   ElsIf item.IsKindOf(PdWsp.cls_WorkspaceModel) Then    
   ElsIf item.IsKindOf(PdWsp.cls_WorkspaceFile) Then    
   End if    
next
 Dim subfolder
'insert folder in root
 Set subfolder = workspace.Children.CreateNew(PdWsp.cls_WorkspaceFolder)
 subfolder.name = "Newfolder(VBS)"
 'insert folder in root at pos 6
 Set subfolder = workspace.Children.CreateNewAt(5, PdWsp.cls_WorkspaceFolder)
 subfolder.name = "Newfolder(VBS)insertedAtPos5"'
   ' add a new folder in this folder
 Set subfolder = subfolder.Children.CreateNew(PdWsp.cls_WorkspaceFolder)
 subfolder.name = "NewSubFolder(VBS)"
 subfolder.AddDocument EvaluateNamedPath("%_EXAMPLES%\pdmrep.rtf")
 subfolder.AddDocument EvaluateNamedPath("%_EXAMPLES%\cdmrep.rtf")
 subfolder.AddDocument EvaluateNamedPath("%_EXAMPLES%\project.pdm")
 subfolder.AddDocument EvaluateNamedPath("%_EXAMPLES%\demo.oom")
 dim lastmodel
 set lastmodel = subfolder.AddDocument (EvaluateNamedPath("%_EXAMPLES%\Ordinateurs.fem"))
 lastmodel.open
 lastmodel.name = "Computers"
 lastmodel.close
 'detaching model from workspace
 lastmodel.delete
workspace.Save "%_EXAMPLES%\Final.SWS"

 


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