Book a Demo

Author Topic: Iterating thru packages  (Read 4923 times)

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Iterating thru packages
« on: November 04, 2014, 02:08:31 pm »
I'm totally confused. Here is an excerpt from the documentation:
The Repository Class is the starting point for all use of the automation interface.  It contains the high level system objects and entry point into the model itself using the Models collection and the other system level collections.
However, there is no mention of the Models Collection in the Reference for the Repository class. Am I missing it somehow???
OK Found this... but I still have this...

What I am (desparately) trying to do it iterate thru every package in a model (including sub-packages) and remove Version Control.

I can get models from the Models collection (even though it seems to be undocumented). I can get a count of packages in a model (although, again, the docs seem to fail me). I don't get a collection of packages, just a collection on the highest level packages, which is a very different thing.

But I haven't figured out how to iterate thru each package and remove version control.

If I try this (using VB script), I get an error:

dim currentModel as EA.Package
dim currentPackage as EA.Package

for j = 0 to currentModel.Packages.Count() - 1
                  currentPackage = currentModel.Packages.GetAt(j)
(etc.)

The error I get is Object doesn't support this property or method. (Indicated on the last code line above).

Now, shouldn't a collection of Packages actually give me all the packages in a model? It doesn't seem to. And shouldn't I be able to assign a Package in a Packages collection to a package?

I'm sure this is obvious to the more experienced among you, so I would greatly appreciate any advice you can offer.
« Last Edit: November 04, 2014, 02:56:21 pm by ssands »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Iterating thru packages
« Reply #1 on: November 04, 2014, 05:58:45 pm »
You'll have to recursively go trough all levels, or you could get a list of packageID's using Repository.SQLQuery() and then instantiate the packages themselves using Repository.GetPackageByID().
For a large model the latter will probably be much faster; and you can use an iteration iso recursion.
There is an example script that does something similar in the standard examples shipped with the product.

I'm no expert in VB Script, but shouldn't you use SET when assigning an object to a variable?
So more like
Code: [Select]
SET currentPackage = currentModel.Packages.GetAt(j)
Geert

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Iterating thru packages
« Reply #2 on: November 05, 2014, 04:02:55 am »
Thanks, Geert. Yes, I figured it out last night (my time). I'm not an expert in VBScript either...I was missing a "Set". And I did end up recursively going through the model.

I suppose I would have appreciated more clarity in the documentation. In this case, it should have stated that the Packages collection only contained packages at that level and did not include sub-levels.