Problem
The top package of an Enterprise Architect Project EAP should be retrieved
Approach
Navigate to the Parent ID until the package return null.
Solution – Lösung
public EA.Package getTopPackage(EA.Package selectedPackage)
{
EA.Package package = null;
try
{
// If it has a parent it won't throw an error
package = repository.GetPackageByID(selectedPackage.ParentID);
}
catch (System.Runtime.InteropServices.COMException)
{
// The selectedPackage is the top package
package = selectedPackage;
}
// If this is not the top package, recall this function
if (package != selectedPackage)
{
package = getTopPackage(package);
}
return package;
}