Author Topic: selecting a Package using Repository.InvokeConstructPicker EA14  (Read 1836 times)

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Hi
I'm trying to select a Package from the project tree using

Code: [Select]
var includedTypes_str = "Package";
id = Repository.InvokeConstructPicker(includedTypes_str);

Even though I selected a package - InvokeConstructPicker is returning an Element
I know this because
Code: [Select]
element = Repository.GetElementByID(elementID); works and
Code: [Select]
package = Repository.GetPackageByID(element.PackageID); fails
The returned element has Type 4 (element)
 - but the name is the name of the package I selected
 - the PackageID  returns the package that encloses the selected package

I suspect I'm getting the Element associated with the Package and not the Element - how can I either get the Package directly or obtain the associated Package object from element?


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: selecting a Package using Repository.InvokeConstructPicker EA14
« Reply #1 on: June 09, 2022, 03:05:18 am »
You can select the package with the same guid of the package element
This is a vbscript function that does so:

Code: [Select]
'let the user select a package
function selectPackage()
dim documentPackageElementID
documentPackageElementID = Repository.InvokeConstructPicker("IncludedTypes=Package")
if documentPackageElementID > 0 then
dim packageElement as EA.Element
set packageElement = Repository.GetElementByID(documentPackageElementID)
dim package as EA.Package
set package = Repository.GetPackageByGuid(packageElement.ElementGUID)
else
set package = nothing
end if
set selectPackage = package
end function

Geert

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: selecting a Package using Repository.InvokeConstructPicker EA14
« Reply #2 on: June 09, 2022, 06:51:16 am »
Great - thanks Geert

For completeness, if you are allowing the user to select a Package or some other element type then you can test the Type of the returned element - and if its "Package" get the package - like so in JS

var element_type = "Package,Class,Component,Activity,Action";
var includedTypes_str = "IncludedTypes="+element_type;
var elementID = Repository.InvokeConstructPicker(includedTypes_str);
var element = Repository.GetElementByID(elementID);
if (element.Type == "Package") {
   element = Repository.GetPackageByGuID(element.ElementGUID);
}