Book a Demo

Author Topic: How to determine a subpackage programmatically?  (Read 4960 times)

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
How to determine a subpackage programmatically?
« on: April 01, 2010, 11:15:05 pm »
Hello guys,

I`m having a problem determining a subpackage of a model (with a JScript)

Here`s my example:

MyModel
  UpperPackage A
       SubPackage B
            SubSubPackage C

I want to get 'SubSubPackageC' with a JScript, how can I do this?

This far, I have the following:

Code: [Select]
var theModel as EA.Package;
theModel = Repository.Models.GetByName("MyModel");                     var anforderungPackage as EA.Package;
anforderungPackage = theModel.Packages.GetByName("SubSubPackage C");      


Well, when getting to the last line, I receive an 'IndexOutOfBounds' error.

Hope you can help me.


Best regards,
palim
« Last Edit: April 01, 2010, 11:15:44 pm by palim »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to determine a subpackage programmatically
« Reply #1 on: April 02, 2010, 12:45:52 am »
Palim,

You can either recurse through the packages using Package.Packages, or you can use an SQL Query to find the package with the given name.
I would choose for the last option. (since that is a lot faster)

use Repository.SQLquery to get the id of the package, and then Repository.GetPackageByID to get the package.

Geert

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to determine a subpackage programmatically
« Reply #2 on: April 02, 2010, 12:54:29 am »
Quote
Palim,

You can either recurse through the packages using Package.Packages, or you can use an SQL Query to find the package with the given name.
I would choose for the last option. (since that is a lot faster)

use Repository.SQLquery to get the id of the package, and then Repository.GetPackageByID to get the package.

Geert

Okay, I`ll try it.
Thank you.

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to determine a subpackage programmatically
« Reply #3 on: April 08, 2010, 12:54:40 am »
Quote
Quote
Palim,

You can either recurse through the packages using Package.Packages, or you can use an SQL Query to find the package with the given name.
I would choose for the last option. (since that is a lot faster)

use Repository.SQLquery to get the id of the package, and then Repository.GetPackageByID to get the package.

Geert


Hello,

I`ve tried it, but unfortunately, I´m not getting it done.

First of all:
What does the SQL command have to look like?
I tried it with "select ID from t_package where name = 'acme'"
Is it correct?

Next, I wanted to test it in a VBScript in EA before implementing it into my Excel macro.
For that, I used the following code:
Code: [Select]
dim repository as EA.Repository
dim package as EA.Package
dim id

id = repository.GetPackageByID(EA.Repository.SQLQuery("select ID from t_package where name = 'acme'"))
When getting to the last line, I`m getting a 'The variable is not defined' error.
But defining the variable 'id' as integer doesn`t work either.

Do you know a possible solution?


Best regards,
palim
« Last Edit: April 08, 2010, 12:56:29 am by palim »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to determine a subpackage programmatically
« Reply #4 on: April 08, 2010, 08:42:05 am »
SQLQuery() "Returns an XML formatted string value of the resulting recordset."

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to determine a subpackage programmatically
« Reply #5 on: April 08, 2010, 02:10:21 pm »
Palim,

The API isn't equipped with the Do what I meantm module yet.
So until that is implemented I'm afraid you'll have to RTFM.
I don't think "ID" is a column in the t_package table, and as Simon pointed out, passing an xml string to an operation that requires an integer isn't going to work out very well either.

Geert

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to determine a subpackage programmatically
« Reply #6 on: April 08, 2010, 04:26:55 pm »
Quote
Palim,

The API isn't equipped with the Do what I meantm module yet.
So until that is implemented I'm afraid you'll have to RTFM.
I don't think "ID" is a column in the t_package table, and as Simon pointed out, passing an xml string to an operation that requires an integer isn't going to work out very well either.
Geert

Well, I admit that I blindly used the two functions you mentioned in your previous post. And yes, that might lead to the conclusion of the Do what I meantm module.

Regarding the documentation:
I`m generally missing way more tutorials.
I`m pretty new to Enterprise Architect, but to me the API leaves more questions than answers.

Regarding my problem:
I guess it will be less effort to iterate recursively over a model and determine a package.


Best regards,
palim

« Last Edit: April 08, 2010, 04:27:30 pm by palim »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to determine a subpackage programmatically
« Reply #7 on: April 08, 2010, 04:40:26 pm »
Palim,

In this topic I added a snippet that uses the SQLQuery operation to get id's.

Geert