Book a Demo

Author Topic: VBA - How to see the root packages & How to create a root package  (Read 7824 times)

rmvanderlinden

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Hi,


From the root I am able to create a view and from the view a package. Now I have multiple root packages, and I am unable to walk through the root package to check their names. If the desired root package is not found, I want to create it.
Question is How to do this?
BTW: I do not want to rely on selecting the right package in EA, but navigate to it myself.

My code below. Path can be "MyModel/MyView/MyPackage"

Public Function getPackage(ByVal Path As String) As Package
    Dim EAPath() As String
    Dim Elements As EA.Collection
    Dim Package As EA.Package
    Dim subPackage As EA.Package
    Dim ID As Integer
    Dim pID As Integer
    Dim i As Integer
    Dim pFound As Boolean
   
    EAPath = Split(Path, "/")
    '
    If EARepos Is Nothing Then
        Set EARepos = Me.getCurrentRepository(True)
    End If
    '
    ' Find the root package
    '
    Set Package = EARepos.GetTreeSelectedPackage()
    pID = Package.ParentID
    Do While pID > 0
        Set Package = EARepos.GetPackageByID(pID)
        pID = Package.ParentID
    Loop
    ID = Package.PackageID
    Set Package = EARepos.GetPackageByID(ID)
    If Package.name <> EAPath(0) Then
        MsgBox "Unable to locate root package '" & EAPath(0) & "'"
        Set getPackage = Nothing
    Else
        '
        ' Create/navigate to Path
        '
        For i = LBound(EAPath) + 1 To UBound(EAPath)
            pFound = False
            For Each subPackage In Package.Packages
                If subPackage.name = EAPath(i) Then
                    ID = subPackage.PackageID
                    Set Package = EARepos.GetPackageByID(ID)
                    pFound = True
                    Exit For
                End If
            Next
            If Not pFound Then
                Set subPackage = Package.Packages.AddNew(EAPath(i), "")
                Call subPackage.Update
                Set Package = subPackage
            End If
        Next
        Set getPackage = Package
    End If
End Function
« Last Edit: February 21, 2025, 12:09:38 am by rmvanderlinden »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBA - How to see the root packages & How to create a root package
« Reply #1 on: February 21, 2025, 08:59:38 am »
Use Repository.Models

Geert

rmvanderlinden

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: VBA - How to see the root packages & How to create a root package
« Reply #2 on: February 24, 2025, 08:18:20 pm »
Thank you for the reply and direction. I got it working  :)