Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: yonatan.lehman on June 09, 2022, 02:24:27 am
-
Hi
I'm trying to select a Package from the project tree using
var includedTypes_str = "Package";
id = Repository.InvokeConstructPicker(includedTypes_str);
Even though I selected a package - InvokeConstructPicker is returning an Element
I know this because
element = Repository.GetElementByID(elementID);
works and
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?
-
You can select the package with the same guid of the package element
This is a vbscript function that does so:
'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
-
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);
}