Skip to Content

How to get extended attribute values using VB script in the PowerDesigner repository

I am trying to write a script that would scan logical data models in the repository of PowerDesigner and retrieve the value of a particular extended attribute using GetExtendedAttribute without any success, the variable stays invariably empty.

I am using the following function:

Sub GetAttributes (curEntity) 'where curEntity is the entity currently being scanned
   ExtAttr = "PMI LDM Formatting.LOV" 'LOV is boolean type
   For each curAttr in curEntity.ChildObjects
      if curAttr.ClassName = "Entity Attribute" then
         output curAttr.name & " - " & curAttr.ClassName
         x = curAttr.GetExtendedAttribute (ExtAttr,1)
         output x
      end if
   Next
End Sub

I have spent some time trying to find examples on how to retrieve extended attributes values from the PowerDesigner repository without any success.

The version used is 16.6 SP04.

Any tips are welcome

Pascal

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Posted on Dec 11, 2019 at 09:35 AM

    Bonjour Pascal :)

    The fact that the model is in the repository should not make any difference to your script. I think your issue is the use of ChildObjects; use the 'Attributes' collection instead. this one works for me:

    dim mdl, ent, curAttr
    for each ent in activemodel.entities
       if ent.name = "Deposit Account" then
          GetAttributes ent
       end if
    Next
    
    Sub GetAttributes (curEntity) 'where curEntity is the entity currently being scanned
    '   ExtAttr = "PMI LDM Formatting.LOV" 'LOV is boolean type
       Dim ExtAttr ' George added this
       ExtAttr = "tryit.LOV" 'LOV is boolean type
    '   For each curAttr in curEntity.ChildObjects
       For each curAttr in curEntity.Attributes
          if curAttr.ClassName = "Entity Attribute" then
             output curAttr.name & " - " & curAttr.ClassName
             x = curAttr.GetExtendedAttribute (ExtAttr,1)
             output x
          end if
       Next
    End Sub
    
    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 12, 2019 at 09:17 AM

    Hi George,

    Thanks for your answer. It works perfectly for an opened model. What I am trying to do is to scan the repository directly. Unfortunately, the Attributes collection does not exist for repository objects not entities (at least I haven't found it). Only objects collections are present in the repository and when I run my scipt x is always empty. My entire script looks like this

    Dim repository, connected, ScanDefined, ScanFolder, ScanAll
    Set repository = RepositoryConnection
    ScanDefined = True
    ScanFolder = "Test"
    ScanAll = false
    connected = repository.Connected
    If not connected then
       connected = repository.Open()
    End If
    If connected then
       ' Begin the recursive scan
       ScanRepository repository
       ' Refresh the repository browser
       repository.Refresh
    Else
       ' Log message
       MsgBox "The repository needs to be connected or default connexion should be operational"
    End If
    ' The recursive procedure that scan folders and extracts models
    Sub ScanRepository (folder)
       ' check the parameters
       If folder is Nothing then
          Exit Sub
       End If
       ' Log message in the output
       if folder.name = ScanFolder and ScanDefined then
          output "Scanning the folder " + folder.Name
       end if
       ' Recursive call on sub folders
       'Dim subObject
       For Each subObject in folder.ChildObjects
          ' recurse or extract repository sub-package
          If subObject.IsKindOf(PdRMG.Cls_RepositoryFolder) then
             ScanRepository subObject
          else
             If subObject.IsKindOf(PdRMG.Cls_RepositoryModel) and folder.name = ScanFolder and ScanDefined then
                output "Extracting " & subObject.name & " - " & subObject.ClassName
                for each curEnt in subObject.ChildObjects
                   if curEnt.ClassName = "Entity" then
                      output curEnt.name & " - " & curEnt.ClassName & " - " & curEnt.Stereotype
                      GetAttributes curEnt
                   end if
                next
                'ScanModel subObject
             end if
          End If
       Next
    End Sub
    Sub ScanModel (model)
       For Each subObject in model.ChildObjects
          ' recurse or extract repository sub-package
          If subObject.IsKindOf(PdRMG.cls_RepositoryPackage) then
             ScanModel subObject
          else
             If subObject.ClassName = "Entity" and ScanAll then
                output subObject.name & " - " & subObject.ClassName & " - " & subObject.Stereotype
             elseif subObject.ClassName = "Entity" and subObject.Stereotype = "Reference Data" then
                output subObject.name & " - " & subObject.ClassName & " - " & subObject.Stereotype
             end if
          End If
       Next
    End Sub
    Sub GetAttributes (curEntity)
       For each curAttr in curEntity.ChildObjects
          if curAttr.ClassName = "Entity Attribute" then
             output curAttr.name & " - " & curAttr.ClassName
             x = curAttr.GetExtendedAttribute("PMI LDM Formatting.[LOV]")
             output x
          end if
       Next
    End Sub

    it works fine for every information except the extended attribute.

    Cheers

    Pascal

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 12, 2019 at 11:06 AM

    I suspect the extended attributes are not available unless you actually open the model

    Add comment
    10|10000 characters needed characters exceeded