Powerdesigner VBA - how to switch active model

687 views Asked by At

Working with powerdesigner models with excel vba. I have multiple models open that I am trying to access. In my code I can easily access the current active model using:

Dim pd_App As PDCommon.Application
Set pd_App = New PDCommon.Application
Dim baseModel As PdPDM.Model
Set baseModel = pd_App.ActiveModel

Is there a way to switch the active model to another model that is also open? I've looked through the methods available and do not see any methods that can perform this task.

Thanks

2

There are 2 answers

0
pascal On

I understand it could have side-effects, but the best I can imagine is to use OpenView.

option explicit

if SelectDiagram("diagone") then
   output "model selected: " & activemodel.name
end if

' try to activate a model by its default diagram name
' returns true if the model was opened
function SelectDiagram(name)
   dim m
   for each m in models
      if m.defaultdiagram.name = name then
         m.defaultdiagram.openview
         SelectDiagram = true
         exit function
      end if
   next
   SelectDiagram = false
end function
0
Chris Grenz On

Two options (this is more vbScript...adjust as needed):

1) Open the models using VBA and use the object referenced from OpenModel:

Set modelBase = pd_App.OpenModel(pathBase, omf_DontOpenView)

2) If the models are already open (as I'm inferring from your question), you can interrogate the Workspace and choose from there:

For Each model In pd_App.ActiveWorkspace.Children If model.Name = "My Model" Then Set theModelIWant = model : Exit For Next