Skip to Content

Scripting: Select Model from OpenedModel Collection

Hello Community,

i am searching for the function or the method call to get a specific model from the List "Models" (which contains all opened models)

In PowerShell I can achieve this by

$powerDesigner = New-Object -com powerdesigner.application

$targetModel = $powerDesigner.Models | Where Code -eq $targetModelCode

In PowerShell I then have the model object in the variable targetModel.

I need the same now in VBScript.

Is there some kind of method like FindChildByCode for the Model List? The documentation says that Models is a global object reference list, but I don´t see a method to get a specific item out of this list...

Kind regards

Stephan

Add comment
10|10000 characters needed characters exceeded

3 Answers

  • Posted on Oct 16, 2019 at 03:02 PM

    I don't think you can do what you ask, as the collection is not a Named Object. You'll have to resort to this (someone with more programming experience may come up with a better approach):

    dim mdl
    for each mdl in models
       if mdl.code = "PRODUCTS_AND_SERVICES_METAMODEL" then output mdl
    next
    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 24, 2019 at 05:45 AM

    Perhaps something like this:

    set ws = ActiveWorkspace

    for each wsmdl in ws.children

    if wsmdl.modelType = "PDM" and not wsmdl.ModelObject is Nothing then

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2019 at 11:40 AM

    My current solution is to directly address the models via their unique filepath:

    '#Get PowerDesigner window as new object
    Set PD = CreateObject("PowerDesigner.Application")
    Output "  PowerDesigner window is loaded"
    '#Select target and source model as objects
    Dim filenameTargetModel, filenameOldSourceModel, filenameNewSourceModel
    filenameTargetModel = "C:\GitRepos\xxx" filenameNewSourceModel = "C:\GitRepos\yyy" filenameOldSourceModel = "C:\GitRepos\zzz" Set targetModel = PD.OpenModel(filenameTargetModel) Set newSourceModel = PD.OpenModel(filenameNewSourceModel) Set oldSourceModel = PD.OpenModel(filenameOldSourceModel)
    Add comment
    10|10000 characters needed characters exceeded