Ciel
Ciel

Reputation: 591

Sparx Enterprise Architect scripting: Enumerate Package Elements

Using JScript, I'd like to enumerate the Elements under a specific Package.

I've received #OBJECTID#, which is the Id of the Package's Element.

I've used that to get the Element.

But when I Count the elements, they're always 0.

What step did I miss?

function devTest()
{
    var package = Repository.GetPackageByGuid("{2255D8C8-F1BB-4069-BDAF-8B303D108C62}");

    // When testing use the Element associate to the Package, not 
    // the Package ID itself (Pretty sure that that 
    // this equivalent to the #OBJECTID# macro).
    var packageElementId = package.Element.ElementID; //NOT: package.PackageID;

    var packageElement = Repository.GetElementByID(packageElementId);

    var elementCollection = packageElement.Elements();
    Session.Output("Element Count: " + elementCollection.Count());

    //ALWAYS ZERO. Not showing Classes and Attributes that are nested under the Package.
}

Thanks for the help!

Upvotes: 0

Views: 1053

Answers (1)

Ciel
Ciel

Reputation: 591

Turned out that i needed the the GetPackageByGuid method to get back to the package associated to the element. It seems the Package's Elements collection is the correct one to use. Go figure...

//Get back to the package that is related to the Element before you count Elements:
var package = Repository.GetPackageByGuid(packageElement.ElementGUID);
var elementCollection = package.Elements;
Session.Output("Element Count: " + elementCollection.Count());

Upvotes: 2

Related Questions